#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
#include<sstream>
using namespace std;
typedef long long ll;

struct Data
{
	int score, num;
	bool operator < (const Data a) const
	{
		return (score == a.score) ? num < a.num : score > a.score;
	}
};

int main(){
	int M;
	while(cin >> M, M)
	{
		Data s[40];
		for(int i = 0; i < M; i++)
		{
			cin >> s[i].num;
			s[i].score = 0;
			queue<int> latte;

			for(int j = 1; j <= 10; j++)
			{
				int pin[2] = {};
				for(int k = 0; k < 2; k++)
				{
					cin >> pin[k];
					int size = latte.size();
					for(int l = 0; l < size; l++)
					{
						if(latte.front() == 2) latte.push(1);
						latte.pop();
						s[i].score += pin[k];
					}
					if(j < 10 && pin[k] == 10) break;
				}
				s[i].score += pin[0] + pin[1];
				if(j == 10 && pin[0] + pin[1] >= 10)
				{
					cin >> pin[0];
					s[i].score += pin[0];
				}
				if(j == 10) break;
				if(pin[0] == 10) latte.push(2);
				else if(pin[0] + pin[1] == 10) latte.push(1);
			}
		}
		sort(s, s + M);
		for(int i = 0; i < M; i++)
		{
			printf("%d %d\n", s[i].num, s[i].score);
		}
	}
	return 0;
}