#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

struct S
{
	int number,result;
	bool operator>(const S& other) const {
		return result == other.result ? number < other.number : result > other.result;
	}
};

int main()
{
	int m;
	while(cin >> m, m){
		cin.ignore();
		S s[41];
		for(int i = 0; i < m; ++i){
			int number;
			vector<int> v1,v2;
			string str;
			
			getline(cin,str);
			stringstream ss(str);
			ss >> number;
			int temp;
			while(ss >> temp){
				v1.push_back(temp);
			}			
			v2 = v1;
			
			int n = 1, point = 0, knock;
			int twice = 0;
			bool f = false;
			int prev = -1;
			for(int j = 0; j < v1.size(); ++j){
				if(prev == -1){
					if(v1[j] == 10){
						if(!(n >= 10)){
							v2[j + 1] += v1[j + 1];
							v2[j + 2] += v1[j + 2];
						}
						n++;
						prev = -1;
						continue;
					}
					prev = v1[j];
				} else {
					if(v1[j] + prev ==10){
						if(!(n >= 10))v2[j + 1] += v1[j + 1];
					}
					prev = -1;
					n += 1;
				}
			}
			point = accumulate(v2.begin(),v2.end(),0);
			s[i].number = number; s[i].result = point;
		}
		sort(s,s + m, greater<S>());
		for(int i = 0; i < m; ++i){
			cout << s[i].number << ' ' << s[i].result << endl;
		}
	}
}