#include <iostream>
#include <algorithm>

struct Player {
	int id;
	int score;
	Player() {}
	Player(int id, int score) : id(id), score(score) {}
};
bool operator > (const Player& p1, const Player& p2) {
	if (p1.score > p2.score) return true;
	else if (p1.score < p2.score) return false;
	else return p1.id < p2.id;
}

int getScore(int s[], int n)
{
	int* frame = new int[n];
	bool* strike = new bool[n];
	bool* spare = new bool[n];
	for (int i=0; i<n; i++) { strike[i] = false; spare[i] = false; }
	frame[0] = 0;
	int s_frame[10];
	for (int i=0; i<10; i++) s_frame[i] = 0;
	int thrownum = 0;
	for (int i=0; i<n; i++) {
		if (thrownum == 0) {
			if (s[i] == 10) {
				strike[i] = true;
				frame[i+1] = frame[i] + 1;
			}
			else {
				frame[i+1] = frame[i];
				thrownum = 1;
			}
			s_frame[frame[i]] += s[i];
			if (i>1) {
				if (strike[i-2]) s_frame[frame[i-2]] += s[i];
			}
			if (i>0) {
				if (strike[i-1]) s_frame[frame[i-1]] += s[i];
				if (spare[i-1])  s_frame[frame[i-1]] += s[i];
			}
		}
		else if (thrownum == 1) {
			if (s[i-1] + s[i] == 10) {
				spare[i] = true;
			}
			if (frame[i] == 9) {
				if (spare[i] || strike[i-1] || strike[i]) {
					frame[i+1] = frame[i];
					thrownum = 2;
				}
			}
			else {
				frame[i+1] = frame[i] + 1;
				thrownum = 0;
			}
			s_frame[frame[i]] += s[i];
			if (i>1) {
				if (strike[i-2]) s_frame[frame[i-2]] += s[i];
			}
			if (i>0) {
				if (strike[i-1]) s_frame[frame[i-1]] += s[i];
				if (spare[i-1])  s_frame[frame[i-1]] += s[i];
			}
		}
		else { // thrownum == 2
			s_frame[frame[i]] += s[i];
		}
	}
	int res = 0;
	for (int i=0; i<10; i++) res += s_frame[i];
	delete[] frame;
	delete[] strike;
	delete[] spare;
	return res;
}

int main()
{
	int score[30];
	std::string input;
	std::string sn; int n;
	while (true) {
		getline(std::cin, sn); n = std::stoi(sn);
		if (n==0) break;
		Player* players = new Player[n];
		for (int i=0; i<n; i++) {
			getline(std::cin, input);
			int id;
			int offset = 0;
			int pos;
			int index = 0;
			int s;
			pos = input.find(' ', offset);
			id = std::stoi(input.substr(offset, pos-offset));
			offset = pos + 1;
			while ( (pos = input.find(' ', offset)) != std::string::npos ) {
				s = std::stoi(input.substr(offset, pos-offset));
				score[index] = s; index++;
				offset = pos + 1;
			}
			s = std::stoi(input.substr(offset));
			score[index] = s; index++;
			players[i] = Player(id, getScore(score, index));
		}
		std::sort(players, players + n, std::greater<Player>());
		for (int i=0; i<n; i++) {
			std::cout << players[i].id << " " << players[i].score << std::endl;
		}
		delete[] players;
	}
	return 0;
}

