#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>

using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		cin.ignore();
		pair <int, int> data[40];
		string str;
		for (int i = 0; i < n; i++){
			getline(cin, str);

			stringstream ss(str);
			vector <int> pin;
			for (int x; ss >> x;){
				pin.push_back(x);
			}

			int score = 0;
			for (int frame = 1, j = 1; frame <= 10; frame++){
				if (frame == 10){
					while (j < pin.size()){
						score += pin[j];
						j++;
					}
					break;
				}
				if (pin[j] == 10){
					// st
					score += pin[j] + pin[j + 1] + pin[j + 2];
					j++;
				}
				else {
					score += pin[j] + pin[j + 1];
					if (pin[j] + pin[j + 1] == 10){
						// sp
						score += pin[j + 2];
					}
					j += 2;
				}
			}
			data[i].first = -score;
			data[i].second = pin[0];
		}
		sort(data, data + n);
		for (int j = 0; j < n; j++){
			cout << data[j].second << " " << -data[j].first << endl;
		}
	}

	return 0;
}