#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int m,id[40];
pair<int,int> p[40];

int main(){
	while(cin>>m&&m){
		rep(i,m){
			cin>>p[i].second;
			int f=1,n,b=0,b2=0,sc=0,sec=0,prv,thi=0;
			while(f<11){
				cin>>n;
				sc+=n;
				if(b2>0){sc+=n*2;b2--;b--;if(!b){b=b2;b2=0;}}
				else if(b>0){sc+=n;b--;}
				//cout<<f<<"-"<<sec+1<<" "<<n<<" "<<sc<<endl;
				if(f==10){
					if(sec==2)break;
					sec+=1;
					if(n==10||sec>1&&prv+n==10)thi=1;
					//cout<<sec<<thi<<endl;
					if(sec==2&&!thi)break;
				}
				else{
					if(!sec){
						if(n==10){f++;if(b>0)b2=2;else b=2;}
						else sec=1;
					}
					else{
						sec=0;f++;
						if(prv+n==10)b=1;
					}
				}
				prv=n;
			}
			p[i].first=-sc;
		}
		sort(p,p+m);
		rep(i,m)cout<<p[i].second<<" "<<-p[i].first<<endl;
	}
}