#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		vector<pint> vp(n);
		int i;
		int f,s1,s2;
		int d;
		int score;
		for(i=0;i<n;i++){
			f=1;
			d=0;
			score=0;
			cin>>vp[i].second;
			while(f<10){
				cin>>s1;
				if(d==3){
					score+=s1*3;
				}else if(d==0){
					score+=s1;
				}else{
					score+=s1*2;
				}
				d/=2;
				if(s1==10){
					d|=2;
				}else{
					cin>>s2;
					if(d==0){
						score+=s2;
					}else{
						score+=s2*2;
					}
					d=0;
					if(s1+s2==10)d=1;
				}
				f++;
			}
			cin>>s1;
			if(d==3){
				score+=s1*3;
			}else if(d==0){
				score+=s1;
			}else{
				score+=s1*2;
			}
			d/=2;
			cin>>s2;
			if(d==0){
				score+=s2;
			}else{
				score+=s2*2;
			}
			if(s1+s2>=10){
				score+=in();
			}
			vp[i].first=score;
		}
		while(!vp.empty()){
			int r=0;
			for(i=1;i<vp.size();i++){
				if(vp[r].first<vp[i].first||vp[r].first==vp[i].first&&vp[r].second>vp[i].second)
					r=i;
			}
			cout<<vp[r].second<<" "<<vp[r].first<<endl;
			vp[r]=vp[vp.size()-1];
			vp.pop_back();
		}
	}
	return 0;
}