import std.stdio;
import std.array;
import std.conv;


void main(){
	int m, sum;
	string[] str;
	while (readf("%d\n", &m), m) {
		int[int] map;
		int[] order;
		foreach (i; 0..m) {
			int[] n;
			sum = 0;
			str = split(readln());
			foreach (s; str) n ~= to!int(s);
			for (int j = 1, r = 1; r <= 10; j++, r++) {
				if(r == 10){
					foreach (k; n[j..$]) sum += k;
				} else if (n[j] == 10) {
					sum += 10 + n[j+1] + n[j+2];
				} else if (n[j] + n[j+1] == 10) {
					sum += 10 + n[j+2];
					j++;
				} else {
					sum += n[j] + n[j+1];
					j++;
				}
			}
			map[n[0]] = sum;

			for (int j = 0; j <= order.length; j++) {
				if (j == order.length || map[order[j]] < sum || (map[order[j]] == sum && order[j] > n[0])) {
					order.insert(j, n[0]);
					break;
				}
			}
		
		}
		foreach (i; order) writeln(i, " ", map[i]);
	}
}