import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	int n;
	while (n = readln.chomp.to!int, n) {
		auto mem = new int[][](n, 2);
		foreach (i; 0..n) {
			auto m = readln.split.map!(to!int);
			auto score = m[1..m.length].reduce!("a+b");
			
			int j = 1;
			foreach (_; 1..10) {
				if (m[j] == 10) {
					score += m[j+1] + m[j+2];
					j++;
				} else if (m[j] + m[j+1] == 10) {
					score += m[j+2];
					j += 2;
				} else {
					j += 2;
				}
			}
			mem[i][0] = m[0];
			mem[i][1] = score;
		}
		mem = mem.sort!("a[0] < b[0]").array;
		foreach (e; mem.sort!("a[1] > b[1]")) {
			writeln(e[0], " ", e[1]);
		}
	}
}