#include <iostream>
#include <string>
#include <stack>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		priority_queue<P> pq;
		for (int i = 0; i < n; i++) {
			P p;
			cin >> p.second;
			vector<int> hyou(21, 0);
			int a;
			for (int j = 0; j < 10; j++) {
				cin >> a;
				if (j != 9) {
					if (a == 10) {
						hyou[j*2] = a;
						hyou[j*2+1] = -1;
					} else {
						hyou[j*2] = a;
						cin >> hyou[j*2+1];
					}
				} else {
					if (a == 10) {
						hyou[j*2] = a;
						cin >> hyou[j*2+1] >> hyou[j*2+2];
					} else {
						hyou[j*2] = a;
						cin >> hyou[j*2+1];
						if (a+hyou[j*2+1] == 10) {
							cin >> hyou[j*2+2];
						}
					}
				}
			}
			p.first = 0;
			for (int j = 0; j < 9; j++) {
				p.first += hyou[j*2];
				if (hyou[j*2] == 10) {
					p.first += hyou[j*2+2];
					if (hyou[j*2+3] == -1) {
						p.first += hyou[j*2+4];
					} else {
						p.first += hyou[j*2+3];
					}
				} else {
					p.first += hyou[j*2+1];
					if (hyou[j*2]+hyou[j*2+1] == 10) {
						p.first += hyou[j*2+2];
					}
				}
			}
			p.first += hyou[18]+hyou[19]+hyou[20];
			pq.push(p);
		}
		while (!pq.empty()) {
			P pp = pq.top();
			pq.pop();
			stack<int> str;
			str.push(pp.second);
			while (!pq.empty() && (pq.top()).first == pp.first) {
				str.push((pq.top()).second);
				pq.pop();
			}
			while (!str.empty()) {
				cout << str.top() << ' ' << pp.first << endl;
				str.pop();
			}
		}
	}
	return 0;
}