#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n&&n){
		vector<pair<int,int> >dat;
		while(n--){
			int mem;
			cin>>mem;
			vector<int> scr;
			int a,b,c;
			for(int i=0;i<10;i++){
				cin>>a;
				scr.PB(a);
				if(a!=10||i==9){
					cin>>b;
					scr.PB(b);
				}else continue;
				if(i==9&&(a+b>=10)){
					cin>>c;
					scr.PB(c);
				}else continue;
			}
			int ans=0,k=0;
			for(int i=0;i<9;i++){
				if(scr[k]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k++;
					continue;
				}
				if(scr[k]+scr[k+1]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k+=2;
					continue;
				}
				ans+=scr[k]+scr[k+1];
				k+=2;
			}
			while(k<scr.size())ans+=scr[k++];
			dat.PB(MP((-1)*ans,mem));
		}
		sort(dat.begin(),dat.end());
		for(int i=0;i<dat.size();i++){
			cout<<dat[i].second<<" "<<dat[i].first*(-1)<<endl;
		}
	}
}