#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

enum{NONE,STRIKE,SPARE};

bool compare(pii a,pii b)
{
	return a.second==b.second?a.first<b.first:a.second>b.second;
}

int main()
{
	for(int m;cin>>m,m;){
		vector<pii> res;
		rep(i,m){
			int n; cin>>n;
			int score=0;
			int flg[2]={};
			rep(j,10){
				int p[3];
				if(j==9){
					rep(k,3){
						cin>>p[k];
						score+=p[k];
						if(flg[0]==STRIKE) score+=p[k];
						if(flg[1]) score+=p[k];
						flg[0]=flg[1];
						flg[1]=NONE;
						if(k==1 && p[0]+p[1]<10)
							break;
					}
				}
				else{
					int p[2];
					rep(k,2){
						cin>>p[k];
						score+=p[k];
						if(flg[0]==STRIKE) score+=p[k];
						if(flg[1]) score+=p[k];
						flg[0]=flg[1];
						if(p[k]==10){
							flg[1]=STRIKE;
							break;
						}
						else if(k==1 && p[0]+p[1]==10)
							flg[1]=SPARE;
						else
							flg[1]=NONE;
					}
				}
			}
			res.push_back(mp(n,score));
		}
		sort(allof(res),compare);
		rep(i,res.size())
			cout<<res[i].first<<" "<<res[i].second<<endl;
	}
	
	return 0;
}