#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct bowling
{
	int id,score;
	//bowling(int id,int score):id(id),score(score){};
	bool operator <(const bowling &t)const{
		if(score!=t.score)return score >t.score;
		return id <t.id;
	}
};

int main(){
	int n;
	while(cin>>n,n){
		bowling data[40];
		int pos = 0;
		int N =n;
		cin.ignore();
		while(n--){
			string str;
			getline(cin,str);
			//cout <<"str = "<<str<<endl;
			stringstream ss(str);
			int id;
			ss >>id;
			int a[30]={0};
			for(int j =0;ss>>a[j];){
				j++;
			}
			//cout <<"test"<<endl;
			int scr = 0;
			int x = 0;
			//cout <<"pos = "<<pos<<endl;
			for(int i =1;;i++){
				if(i!=10){
					if(a[x]==10){
						scr +=(10+a[x+1]+a[x+2]);
						x++;
					}
					else if(a[x]+a[x+1]==10){
						scr +=(10+a[x+2]);
						x +=2;
					}else{
						scr +=(a[x]+a[x+1]);
						x +=2;
					}
				}else{
					scr +=(a[x]+a[x+1]+a[x+2]);
					break;
				}
			}
			bowling cs={id,scr};
			data[pos++] =cs;
		}
		sort(data,data+N);
		for(int i =0;i <N;i++){
			cout <<data[i].id<<" "<<data[i].score<<endl;
		}
	}
	return 0;
}