#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

struct game{
	int i;
	vector<int> point;
	game() : i(0){}
	game(int i) : i(i){}
	bool strike(){ return point[0] == 10;}
	bool spare(){ return point[0] + point[1] == 10;}
	bool fill(){ return strike() || sz(point) == 2;}
	int sum(){ return accumulate(point.begin(),point.end(),0); }
};

bool CMP(const Pii& l,const Pii &r){ return l.second == r.second ? l.first < r.first : l.second > r.second; }

int main(){
	int n;
	while(cin>>n,n){
		vector<Pii> out;
		FOR(i,n){
			int id; cin>>id;
			string line; getline(cin,line);
			istringstream iss(line);
			vector<game> g(1);
			vector<int> v;
			int a; 
			while(iss>>a){
				v.push_back(a);
				g.back().point.push_back(a);
				if(sz(g) != 10 && g.back().fill())
					g.push_back(game(sz(v)));
			}

			int ans = 0;
			FOR(i,9){
				ans += g[i].sum();
				if(g[i].strike()){
					int c = g[i].i;
					ans += v[c+1] + v[c+2];
				} else if(g[i].spare()){
					ans += v[g[i].i+2];
				}
			}
			ans += g[9].sum();
			out.push_back(Pii(id,ans));
		}
		sort(out.begin(),out.end(),CMP);
		FOR(i,sz(out)){
			printf("%d %d\n",out[i].first,out[i].second);
		}
	}


	return 0;
}