#include <iostream>
#include <algorithm>
using namespace std;

int getPoint() {
	int frames[12][2];
	for (int i = 0; i < 10; i++) {
		cin >> frames[i][0];
		if (frames[i][0] == 10) {
			frames[i][1] = 0;
		}
		else {
			cin >> frames[i][1];
		}
	}
	frames[11][0] = frames[11][1] = 0;
	if (frames[9][0] == 10) {
		cin >> frames[10][0];
		if (frames[10][0] == 10) {
			frames[10][1] = 0;
			cin >> frames[11][0];
		}
		else {
			cin >> frames[10][1];
		}
	}
	else if (frames[9][0] + frames[9][1] == 10) {
		cin >> frames[10][0];
		frames[10][1] = 0;
	}
	
	int result = 0;
	for (int i = 0; i < 10; i++) {
		result += frames[i][0] + frames[i][1];
		if (frames[i][0] + frames[i][1] == 10) {
			result += frames[i + 1][0];
			if (frames[i][0] == 10) {
				if (frames[i + 1][0] == 10) {
					result += frames[i + 2][0];
				}
				else {
					result += frames[i + 1][1];
				}
			}
		}
	}
	return result;
}

int main () {
	int m;
	while (cin >> m, m) {
		pair<int, int> results[m];
		for (int i = 0; i < m; i++) {
			cin >> results[i].second;
			results[i].first = -getPoint();
		}
		sort(results, results + m);
		for (int i = 0; i < m; i++) {
			cout << results[i].second << ' ' << -results[i].first << endl;
		}
	}
	return 0;
}