#include<iostream>
using namespace std;

int *p,*n,*ans,m;

void sort(){
	int tmp;
	for(int i=m; i>0; i--){
		for(int k=0; k<i-1; k++){
			if(p[ans[k]] < p[ans[k+1]] || (p[ans[k]] == p[ans[k+1]] && n[ans[k]] > n[ans[k+1]])){
				tmp = ans[k];
				ans[k] = ans[k+1];
				ans[k+1] = tmp;
			}
		}
	}
}

int main(){
	int pin1,pin2,game,thr;
	bool sp,st1,st2;
	while(true){
		cin >> m;
		if(!m)
			return 0;
		p = new int[m];
		n = new int[m];
		ans = new int[m];
		for(int i=0; i<m; i++){
			sp = false;
			st1 = false;
			st2 = false;
			game = 1;
			cin >> n[i];
			p[i] = 0;
			ans[i] = i;
			while(true){
				cin >> pin1;
				if(sp){
					p[i]+=pin1;
					sp = false;
				}
				if(st2){
					p[i] += pin1;
					st2 = false;
				}
				if(st1){
					p[i] += pin1;
					st2 = true;
					st1 = false;
				}
				if(pin1 == 10){
					st1 = true;
				}else{
					cin >> pin2;
					if(st2){
						p[i] += pin2;
						st2 = false;
					}
					pin1 += pin2;
					if(pin1 == 10)
						sp = true;
				}
				p[i] += pin1;
				game++;
				if(game == 10){
					cin >> pin1;
					if(sp){
						p[i] += pin1;
					}
					if(st2){
						p[i] += pin1;
						st2 = false;
					}
					if(st1){
						p[i] += pin1;
						st2 = true;
					}
					p[i] += pin1;
					if(pin1 == 10){
						cin >> pin1;
						if(st2)
							p[i] += pin1;
						p[i] += pin1;
						cin >> pin1;
						p[i] += pin1;
					}
					else{
						cin >> pin2;
						if(st2)
							p[i] += pin2;
						p[i] += pin2;
						if(pin1 + pin2 == 10){
							cin >> pin1;
							p[i] += pin1;
						}
					}
					break;
				}
			}
		}
		sort();
		for(int i=0; i<m; i++)
			cout << n[ans[i]] << ' ' << p[ans[i]] << endl;
		delete[] n;
		delete[] p;
		delete[] ans;
	}
}