#include <iostream>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int, int> P;
int main(){
	int n,a,psum,c,take,f;
	string str,out;
	P tmp,array[40];
	vector<P> plist;
	vector<int> point;
	while(cin >> n,n){
		plist.clear();
		getline(cin,str);
		for(int i = 0;i < n;++i){
			psum = c = take = 0;
			getline(cin,str);
			stringstream buf(str);
			point.clear();
			f = 1;
			while(buf >> out){
				a = atoi(out.c_str());
				if(f) {
					tmp.second = a;
					f = 0;
				}
				else{
					point.push_back(a);
				}
			}
			int k = 0;
			for(int j = 0;j < 10;++j){
				if(point[k] == 10){
					psum += point[k] + point[k + 1] + point[k + 2];
					++k;
				}
				else if(point[k] + point[k + 1] == 10){
					psum += point[k] + point[k + 1] + point[k + 2];
					k += 2;
				}
				else{
					psum += point[k] + point[k + 1];
					k += 2;
				}
			}
			tmp.first = psum;
			plist.push_back(tmp);
			buf.clear();
		}
		sort(plist.begin(),plist.end());
		reverse(plist.begin(),plist.end());
		for(int i = 0;i < plist.size();++i){
			cout << plist[i].second << " " << plist[i].first << endl;
		}
	}
	return 0;
}