#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vector<pii> data(n);
		rep(i, n){
			scanf("%d", &data[i].second);
			
			int point = 0;
			int remain[10] = {0};
			rep(j, 10){
				int pin = 0;
				int roop = 2;
				for(int cnt=0 ; cnt<roop; ++cnt){
					int p;
					scanf("%d", &p);
					rep(k, j){
						if(remain[k]){
							--remain[k];
							point += p;
						}
					}
					pin += p;
					if(pin == 10){
						if(j < 9){
							remain[j] = 2 - cnt;
							break;
						}
						else
							roop = 3;
					}
				}

				point += pin;
			}
			data[i].first = -point;
		}
		
		sort(data.begin(), data.end());
		rep(i, n){
			printf("%d %d\n", data[i].second, -data[i].first);
		}
	}

	return 0;
}