#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct data
{
	int num,ptr;
	bool operator<(const data &c) const
	{
		return (ptr!=c.ptr ? ptr>c.ptr : num<c.num);
	}
};

int main()
{
	int t,i,j,n;
	data tmp;
	while(cin >> n, n)
	{
		vector<data> rank;
		for(int k=0; k<n; k++)
		{
			vector<int> score;

			cin >> tmp.num;
			while(cin.peek() != '\n')
			{
				cin >> t;
				score.push_back(t);
			}
			score.push_back(0);
			score.push_back(0);

			tmp.ptr=0;
			for(i=j=0; i<10; i++)
			{
				if(score[j]==10)
				{
					tmp.ptr += score[j]+score[j+1]+score[j+2];
					j+=1;
				}
				else if(score[j]+score[j+1]==10)
				{
					tmp.ptr += score[j]+score[j+1]+score[j+2];
					j+=2;
				}
				else
				{
					tmp.ptr += score[j]+score[j+1];
					j+=2;
				}
			}
			rank.push_back(tmp);
		}
		sort(rank.begin(), rank.end());
		for(int k=0; k<n; k++)
		{
			cout << rank[k].num << " " << rank[k].ptr << endl;
		}
	}
}