#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<pair<int,int> > infos;
		for(int i = 0; i < n; i++){
			int num;
			cin>>num;
			int frame=1;
			pair<int,int> scores[11];
			int sum=0;
			while(1){
				if(frame==10){
					int sc,sc2;
					cin>>sc>>sc2;
					int sc3=0;
					if(sc==10||sc+sc2>=10){
						cin>>sc3;
					}
					scores[10].first=sc;
					scores[10].second=sc2;
					sum+=sc3+sc+sc2;
					break;
				}
				else{
					int sc;
					cin>>sc;
					if(sc==10){
						scores[frame].first=sc;
						scores[frame].second=-1;
						frame++;
					}
					else{
						int sc2;
						cin>>sc2;
						scores[frame].first=sc;
						scores[frame].second=sc2;
						frame++;
					}
				}
			}
			// {[iXðÁZ
			for(int i = 1; i <= 9; i++){
				sum+=scores[i].first;
				// XgCN
				if(scores[i].first==10){
					sum+=scores[i+1].first;
					// XgCN¾Á½ê
					if(scores[i+1].first==10&&i+1!=10){
						sum+=scores[i+2].first;
					}
					else{
						sum+=scores[i+1].second;
					}
				}
				// XyA
				else if(scores[i].second!=-1&&scores[i].first+scores[i].second==10){
					sum+=scores[i].second;
					sum+=scores[i+1].first;
				}
				else{
					sum+=scores[i].second;
				}
			}
			infos.push_back(make_pair(sum,-num));
		}
		sort(infos.begin(),infos.end(),greater<pair<int,int> >());
		for(int i = 0; i < infos.size(); i++){
			cout<<-infos[i].second<<" "<<infos[i].first<<endl;
		}
	}

	return 0;
}