#include <bits/stdc++.h>
using namespace std;

struct P {
	int id;
	int score;
	bool operator < (const P &t) const {
		if (score != t.score) return score > t.score;
		return id < t.id;
	}
	P(int id, int score): id(id), score(score){}
};

int n;

int main()
{
	while (scanf("%d", &n), n){
		vector<P> ps;
		for (int c = 0; c < n; c++){
			int id;
			scanf("%d", &id);
			
			int score = 0;
			int t = 0;
			int sp = 0;
			int st = 0;
			while (t < 10){
				if (t == 9){
					int a[3] = {};
					int m = 2;
					for (int i = 0; i < m; i++){
						scanf("%d", &a[i]);
						score += a[i] * (1 + sp + st);
						sp = st;
						st = 0;
						if (i == 1 && a[0] + a[1] >= 10) m++;
					}
					t++;
					continue;
				}
				
				int a;
				scanf("%d", &a);
				
				score += a * (1 + sp + st);
				sp = st;
				st = 0;
				
				if (a == 10){
					st++;
					t++;
					continue;
				}
				
				int b;
				scanf("%d", &b);
				
				score += b * (1 + sp + st);
				sp = st;
				st = 0;
				
				
				if (a + b == 10) sp++;
				t++;
			}
			
			ps.push_back(P(id, score));
		}
		
		sort(ps.begin(), ps.end());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", ps[i].id, ps[i].score);
		}
	}
	return 0;
}