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

int main(){
	int m;
	while(cin >> m && m){
		vector< pair<int,int> > OK;
		for(int x = 0 ; x < m ; x++){
			int prev = 0 , ans = 0;
			vector< vector<int> > v;
			int num; cin >> num;
			for(int i = 0 ; i < 10 ; i++){
				int a;
				vector<int> t;
				cin >> a;
				t.push_back(a);
				if(i != 9){
					if(a!=10){
						int b;
						cin >> b;
						t.push_back(b);
					}
				}else{
					if(a==10){
						int b,c;
						cin >> b >> c;
						t.push_back(b);
						t.push_back(c);
					}else{
						int b; cin >> b;
						t.push_back(b);
						if(a+b==10){
							int c;
							cin >> c;
							t.push_back(c);
						}
					}
				}
				v.push_back(t);
			}
			for(int i = 0 ; i < 9 ; i++){
				if(v[i][0]==10){
					ans += v[i][0];
					if(v[i+1].size() < 2){
						ans += v[i+1][0] + v[i+2][0];
					}else{
						ans += v[i+1][0] + v[i+1][1];
					}
				}else if(v[i][0]+v[i][1] == 10){
					ans += 10;
					ans += v[i+1][0];
				}else{
					ans += v[i][0]+v[i][1];
				}
			}
			for(int j = 0 ; j < v[9].size() ; j++)
				ans += v[9][j];
			OK.push_back(make_pair(-ans,num));
		}
		sort(OK.begin(),OK.end());
		for(int i = 0 ; i < OK.size() ; i++)
			cout << OK[i].second << " " << -OK[i].first << endl;
	}
}