#include<iostream>
#include<stdio.h>
#define MAX 1000
using namespace std;
typedef struct Score
{
int score;
int add;
}Score;
Score S[MAX];
int main()
{
int n;
while (cin >>n )
{
for (int i = 0; i < n; i++)
{
int sum = 0;
cin >> S[i].score;
int a = S[i].score;
while (a != 0)
{
sum += a % 10;
a = a / 10;
}
S[i].add = sum;
}
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if (S[i].add < S[j + 1].add)
{
Score a = S[j + 1];
S[j + 1] = S[i];
S[i] =a;
}
else if (S[i].add = S[j + 1].add)
{
if (S[i].score > S[j + 1].score)
{
Score a= S[j + 1];
S[j + 1] = S[i];
S[i] = a;
}
}
}
}
for (int i = 0; i < n; i++)
cout << S[i].score << ' '<< S[i].add<<endl;
}
return 0;
}