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);
			int strike, lane, score, pre = -1;
			foreach (s; m[1..m.length]) {
				score += s;
				if (strike) {
					if (strike > 2) {
						score += 2 * s;
						strike -= 2;
					} else {
						score += s;
						strike--;
					}
				}

				if (lane == 9) continue;

				if (pre == -1) {
					pre = s;
					if (s == 10) {
						strike += 2;
						pre = -1;
						lane++;
					}
				} else {
					if (pre + s == 10) {
						strike++;
					}
					pre = -1;
					lane++;
				}
			}
			mem[i][0] = m[0];
			mem[i][1] = score;
		}
		sort = mem.sort!("a[0] < b[0]");
		foreach (e; mem.sort!("a[1] > b[1]")) {
			writeln(e[0], " ", e[1]);
		}
	}
}