#include<iostream>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

#define MAX_N 10000000

int game[MAX_N][10], x[MAX_N][10][3];
int score[MAX_N][10];
int sum[MAX_N], cust[MAX_N];
int n, cnt, sum2;

pair<int, int>bowling[MAX_N];

int main() {
	while (true) {
		//memset.
		memset(game, 0, sizeof(game));
		memset(x, 0, sizeof(x));
		memset(score, 0, sizeof(score));
		memset(sum, 0, sizeof(sum));
		memset(cust, 0, sizeof(cust));
		memset(bowling, 0, sizeof(bowling));

		cin >> n;
		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			cin >> cust[i];

			for (int j = 0; j < 10; j++) {
				//cin.
				cnt = 0;
				while (true) {
					cin >> x[i][j][cnt];

					//1-9 Frame.
					if (j < 9) {
						if (x[i][j][cnt] == 10) {
							goto Exit;
						}
						if (cnt == 1) {
							goto Exit;
						}
					}

					//10 Frame.
					else {
						if (cnt == 1) {
							if (x[i][j][0] != 10 && x[i][j][1] != 10) {
								goto Exit;
							}
						}
						else if (cnt == 2) {
							goto Exit;
						}
					}

					//End Throw.
					cnt++;
				}
			Exit:;
				game[i][j] = cnt + 1;
			}
		}
		
		//check.
		for (int i = 0; i < n; i++) {

			//sum.
			for (int j = 0; j < 10; j++) {
				sum2 = 0;
				for (int k = 0; k < game[i][j]; k++) {
					sum2 += x[i][j][k];
				}

				//1-9 Frame.
				if (j < 9) {
					//Normal.
					if (sum2 < 10) {
						score[i][j] = sum2;
					}

					//Spair.
					else if (game[i][j] == 2) {
						score[i][j] = 10 + x[i][j + 1][0];
					}

					//Strike!!
					else {
						if (game[i][j] == 1) {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 2][0];
						}
						else {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 1][1];
						}
					}
				}

				//10 Frame.
				else {
					score[i][j] = sum2;
				}
			}

			//Calc.
			for (int j = 0; j < 10; j++) {
				sum[i] += score[i][j];
			}
		}

		//pair-input.
		for (int i = 0; i < n; i++) {
			bowling[i] = make_pair(sum[i], cust[i]);
		}

		//sort.
		sort(bowling, bowling + n, greater<pair<int, int> >());

		//print.
		for (int i = 0; i < n; i++) {
			cout << bowling[i].second << ' ' << bowling[i].first << endl;
		}
	}
	return 0;
}