#include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	while(true){
		int n; cin >> n;
		if(n == 0)break;
		set<pair<int,int>> st;
		string z; getline(cin, z);
		for(int i = 0; i < n; i++){
			string raw;
			getline(cin, raw);
			stringstream ss; ss << raw;
			int id; ss >> id;
			pair<int, int> score;
			vector<pair<int, int>> t(10);
			for(int j = 0; j < 10; j++){
				ss >> t[j].first;
				if(t[j].first == 10 && j != 9)continue;
				if(ss.eof())break;
				ss >> t[j].second;
			}
			for(auto e : t)score.first += e.first + e.second;
//			for(auto e : t)cerr << e.first << "," << e.second << " ";
			int ls = 0;
			if(!ss.eof())ss >> ls;
			score.first += ls;
//			cerr << ls << endl;
//			cerr << score.first << endl;
			for(int j = 0; j < 10; j++){
				if(t[j].first == 10){
					if(j == 9){
						//score.first += t[j].second + ls;
					}
					else{
						score.first += t[j+1].first;
						if(t[j+1].first == 10 && j+1 < 9){
							score.first += t[j+2].first;
						}
						else{
							score.first += t[j+1].second;
						}
					}
				}
				else if(t[j].first + t[j].second == 10){
					if(j == 9){
						//score.first += ls;
					}
					else{
						score.first += t[j+1].first;
					}
				}
//				cerr << score.first << " ";
			}
//			cerr << endl;
			score.first *= -1;
			score.second = id;
			st.insert(score);
		}
//		cerr << st.size() << endl;
		for(auto e : st){
			cout << e.second << " "<< (-e.first) << endl;
		}
	}
	return 0;
}


