#include <iostream>
#include <cstdlib>
#include <vector>
#include <map>
#include <string>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		map<P, int> Map;
		for(int i = 0; i < n; ++i)
		{
			int num;
			cin >> num;
			P p;
			p.second = num;
			string str;
			getline(cin, str);
			str += " ";
			int size = str.size();
			vector<int> Vec;
			int s = 0;
			for(int j = 1; j < size; ++j)
			{
				if(str[j] == ' ')
				{
					Vec.push_back(s);
					s = 0;
				}
				else
				{
					s *= 10;
					s += str[j] - '0';
				}
			}
			int sum = 0;
			size = Vec.size();
			Vec.push_back(0);
			Vec.push_back(0);
			int count = 0;
			int bonus = 0;
			int point = 0;
			int frame = 0;
			for(int i = 0; i < size; ++i)
			{
				if(count % 2 == 0)
				{
					count %= 2;
					point = 0;
					++frame;
				}
				++count;
				if(frame >= 10)
				{
					sum += Vec[i];
					continue;
				}
				point += Vec[i];
				sum += Vec[i];
				if(count == 2 && point == 10)		//spare
				{
					bonus = 1;
				}
				if(count == 1 && point == 10)		//strike
				{
					bonus = 2;
					count = 2;
				}
				if(bonus == 1)
				{
					sum += Vec[i + 1];
					bonus = 0;
				}
				else if(bonus == 2)
				{
					sum += Vec[i + 1] + Vec[i + 2];
					bonus = 0;
				}				
			}
			p.first = sum;
			++Map[p];
		}
		map<P, int>::iterator It = Map.end();
		--It;
		for(int i = 0; i < n; ++i)
		{
			cout << It->first.second << " " << It->first.first << endl;
			--It;
		}
	}
}

int main()
{
	solve();
	return(0);
}