#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
bool desc(pair<int, int> a, pair<int, int> b) {
	if(a.second != b.second) return a.second > b.second;
	else return a.first < b.first;
}
int main() {
	int n, a;
	while(cin >> n, n) {
		vector<pair<int,int> > v;
		rep(i,n) {
			cin >> a;
			int s[10][2] = {}, cnt = 0, b, c, score = 0;
			while(cnt < 9) {
				cin >> b;
				if(b == 10) {
					s[cnt][0] = 10;
					cnt++;
					continue;
				}
				cin >> c;
				s[cnt][0] = b;
				s[cnt][1] = c;
				cnt++;
			}
			cin >> b >> c;
			s[cnt][0] = b;
			s[cnt][1] = c;
			if(b + c >= 10) cin >> score;
			rep(i,9) {
				if(s[i][0] == 10) {
					s[i][0]+=s[i+1][0];
					if(s[i+1][0] == 10 && i != 8) s[i][0] += s[i+2][0];
					else s[i][0] += s[i+1][1];
				} else if(s[i][0] + s[i][1] == 10) s[i][0] += s[i+1][0];
			}
			rep(i,10) {
				rep(j,2) {
					score += s[i][j];
				}
			}
			v.push_back(make_pair(a, score));
		}
		sort(v.begin(), v.end(), desc);
		rep(i,n) {
			cout << v[i].first << " " << v[i].second << endl;
		}
	}
	return 0;
}