#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int n,num[50],score[50]={0},tmp;
	int s_max,ans_num;
	vector<int> pin;

	while(cin>>n){
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>num[i];
			score[i]=0; pin.clear();
			for(int j=0;j<9;j++){
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
				if(tmp==10) continue;
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			}

			cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			if(pin[pin.size()-2]==10 || pin[pin.size()-1]+pin[pin.size()-2]==10){
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			}


			for(int j=0,k=0;j<9;j++){
				if(pin[k]==10){
					score[i]+=pin[k+1]+pin[k+2]; k++;
				}else if(pin[k]+pin[k+1]==10){
					score[i]+=pin[k+2]; k+=2;
				}else{k+=2;}
			}

		}
		
		for(int i=0;i<n;i++){
			s_max=-1;
			for(int j=0;j<n;j++){
				if(score[j]>s_max){ s_max=score[j]; ans_num=j;}
			}
			cout<<num[ans_num]<<" "<<score[ans_num]<<endl;
			score[ans_num]=0;
		}
	}
	
	return 0;
}