#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define fi first
#define sec second
#define pb push_back
int hit[25],frame[25];
bool spare[25],strike[25];
int game(){
	memset(hit,0,sizeof(hit));
	memset(frame,-1,sizeof(frame));
	memset(spare,false,sizeof(spare));
	memset(strike,false,sizeof(strike));
	int cur = 0;
	for(int i=1;i<=9;i++){
		scanf("%d",&hit[cur]);
		frame[cur]=i;
		cur++;
		if(hit[cur-1]==10){
			strike[cur-1]=true;
			continue;
		}
		scanf("%d",&hit[cur]);
		frame[cur]=i;
		if(hit[cur]+hit[cur-1]==10)spare[cur]=true;
		cur++;
	}
	for(int i=10;i<=10;i++){
		scanf("%d",&hit[cur]);
		frame[cur]=i;
		cur++;
		scanf("%d",&hit[cur]);
		frame[cur]=i;
		cur++;
		if(hit[cur-1]+hit[cur-2]<10)break;
		scanf("%d",&hit[cur]);
		frame[cur]=i;
		cur++;
	}
	int ret = 0;
	for(int i=0;i<cur;i++){
		ret += hit[i];
		if(strike[i]){
			ret += hit[i+1];
			ret += hit[i+2];
		}
		if(spare[i])ret += hit[i+1];
	}
	return ret;
}
int main(){
	int m;
	while(1){
		scanf("%d",&m);
		if(m==0)break;
		vector<P> vec;
		for(int i=0;i<m;i++){
			int id;
			scanf("%d",&id);
			int score = game();
			vec.pb(P(-score,id));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i<vec.size();i++){
			printf("%d %d\n",vec[i].sec,-vec[i].fi);
		}
	}
	return 0;
}