#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

void input(vector<vint>& v)
{
	rep(i, 10)
	{
		int f;
		cin >> f;
		  
		v[i][0] = f;
		
		// 2Úª éê
		if(f != 10 || i == 9)
		{
			int s;
			cin >> s;
			
			v[i][1] = s;
		}
	}
	
	// 10t[ÚÌÅãÌ
	if(v[9][0] + v[9][1] == 10 || v[9][1] == 10)
	{
		int l;
		cin >> l;
		
		v[9][2] = l;
	}
}

int calc(vector<vint> v)
{
	// Åã©çßÄ¢­
	// 10t[ÚÌÝÊ

	int res = v[9][0] + v[9][1] + (v[9][2] != -1 ? v[9][2] : 0);
	
	rep(i, 9)
	{
		if(v[i][0] == 10)
		{
			res += 10 + v[i + 1][0] + (v[i + 1][1] != -1 ? v[i + 1][1] : (i < 8 ? v[i + 2][0] : v[i + 1][2]));
		}
		else if(v[i][0] + v[i][1] == 10)
		{
			res += 10 + v[i + 1][0];
		}
		else res += v[i][0] + v[i][1];
	}
	
	return res;
}

bool pred(pint a, pint b)
{
	return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main()
{
    int n;
	while(cin >> n && n)
	{
		vector<pint> pnt(n);
		
		rep(i, n)
		{
			cin >> pnt[i].second;

			vector<vint> v(10, vint(3, -1));
			
			// üÍðó¯æé
			input(v);
			
			// ¾_ðvZ·é
			pnt[i].first = calc(v);
		}
		
		// å«¢Å\[g
		sort(ALL(pnt), pred);
		
		rep(i, n)
			cout << pnt[i].second << " " << pnt[i].first << endl;
	}
}