#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef pair<int, int> P;
typedef pair<int, bool> Q;

int main()
{
	string str = "";
	while (getline (cin, str ) && str != "0" ){
		stringstream ssn (str );
		int n;
		ssn >> n;	
		vector<P> score (n);		
		for (int i = 0; i < n; i++ ){
			
			getline (cin, str );
			stringstream ss (str );
			ss >> score[i].second;
			int m;
			vector<int> p;
			while (ss >> m ){			
				p.push_back (m );
			} // end while
			int s[21] = {0};
			int size = p.size();
			int k = 0;
			for (int j = 0; j < size; j++ ){
				s[k] = p[j];
				if (p[j] == 10 ){
					if (k % 2 == 0 && k < 18 ){
						k++;
					}
				} // end if
				k++;
			} // end for

			vector <Q> g(10);
			for (int j = 0; j < 10; j++ ){
				if (j != 9 ){		
					g[j].first = s[2*j] + s[2*j+1];
					if (s[2*j] == 10 ){
						g[j].second = true;
					}// end if
				}else{
					g[j].first = s[2*j] + s[2*j+1] + s[2*j+2];
				} // end if
			} // end for
			int sum = 0;
			for (int j = 0; j < 10; j++ ){
				int pos = 0;	
				pos += g[j].first;
				if (j != 9 && g[j].first == 10 ){
					if (g[j].second ){
						pos += (g[j+1].second ? 10 + s[2*(j+2)] : s[2*(j+1)] + s[2*(j+1)+1]);
					}else{
						pos += s[2*(j+1)];
					} // end if
				} // end if
				sum += pos;
			} // end for
			score[i].first = -sum;

		} // end for
		sort (ALL (score ) );
		for (int i = 0; i < n; i++ ){
			cout << score[i].second << ' ' << -score[i].first << endl;
		} // end for
	} // end loop
		
	return 0;
}