#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

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

int main(){
	int m, n, t, p, f;
	stringstream ss;
	string s;
	vi v;
	while(cin>>m && m){
		cin.ignore();
		vector<pii> score(m);
		rep(j, m){
			getline(cin,s);
			ss.clear();
			ss<<s;
			ss>>n;
			v.clear();
			while(ss>>t) v.pb(t);
			//rep(i, v.size()) cout<<" "<<v[i];
			//cout<<endl;
			p = t = 0;
			f = 1;
			for(int i = 0; i < v.size() && f <= 10; i++, f++){
				t = v[i];
				if(t == 10){
					if(i+1<v.size())t += v[i+1];
					if(i+2<v.size())t += v[i+2];
					p += t;
					//<<t<<" "<<p<<endl;
					continue;
				}
				t+=v[i+1];
				i++;
				if(t == 10){
					if(i+1< v.size()) t+= v[i+1];
				}
				p+=t;
				//cout<<t<<" "<<p<<endl;
			}
			score[j] = mp(p, -n);
		}
		sort(rall(score));
		rep(i, m){
			cout<<-score[i].se<<" "<<score[i].fi<<endl;
		}
	}
}