#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

struct frame {
	int type;
	vector<int>pins;
	int score;
	frame():type(0), pins(), score(0){

	}
};
int getscore() {
	vector<frame>frames(10);
	int now = 0;
	int num = 0;
	int sum = 0;
	vector<pair<int, int>>ps;
	bool flag = false;
	while (1) {
		int n; cin >> n;
		if (now != 9) {
			if (num == 0) {
				frames[now].pins.push_back(n);
				sum += n;
				if (sum == 10) {
					now++;
					num = 0;
					sum = 0;
					ps.push_back(make_pair(2, n));
				}
				else {
					num++;
					ps.push_back(make_pair(0, n));
				}
			}
			else if (num == 1) {
				frames[now].pins.push_back(n);
				sum += n;
				if (sum == 10) {
					ps.push_back(make_pair(1, n));
				}
				else {
					ps.push_back(make_pair(0, n));
				}
				sum = 0;
				num = 0;
				now++;
			}
		}
		else {
			if (num == 0) {
				sum += n;
				if (sum == 10) {
					sum = 0;
					ps.push_back(make_pair(0, n));
					flag = true;
				}
				else {
					ps.push_back(make_pair(0, n));
				}
			}
			else if (num == 1) {
				sum += n;
				if (sum == 10) {
					sum = 0;
					ps.push_back(make_pair(0, n));
					flag = true;
				}
				else {
					ps.push_back(make_pair(0, n));
				}
				if (!flag)break;
			}
			else if (num == 2) {
				sum += n;
				ps.push_back(make_pair(0, n));
				break;
			}
			num++;
		}
		
	}
	int score = 0;
	for (int i = 0; i < ps.size(); ++i) {
		for (int j = i; j <= i + ps[i].first; ++j) {
			score += ps[j].second;
		}
	}
	return score;
}

int main() {
	
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, int>>ps;
		for (int i = 0; i < N; ++i) {
			int num; cin >> num;
			int ans = getscore();
			ps.emplace_back(ans, 10000 - num);
		}
		sort(ps.begin(), ps.end(), greater<pair<int, int>>());
		for (auto p : ps) {
			cout << 10000 - p.second << " " << p.first << endl;
		}
	}
	return 0;
}