#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int dp[300][300][4];
int main(){
	int n;
	while(cin>>n,n){
		vp out(n);
		rep(i,n){
			int a,b;
			cin>>a;
			out[i].second=a;
			vi co(10);
			int sum=0;
			rep(j,10){
				cin>>a;
				sum+=a;
				rep(k,j)if(co[k]){
					sum+=a;
					co[k]--;
				}
				if(a!=10){
					cin>>b;
					sum+=b;
					rep(k,j)if(co[k]){
						sum+=b;
						co[k]--;
					}
					if(a+b==10)co[j]=1;
				}else co[j]=2;
			}
			rep(j,co[9]){
				cin>>a;
				sum+=a;
				if(co[8]){
					sum+=a;
					co[8]--;
				}
			}
			out[i].first=-sum;
		}
		sort(all(out));
		rep(i,n)cout<<out[i].second<<" "<<-out[i].first<<endl;
	}
}