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

struct score_board {
	int id;
	int score;
	int frames[32];
	int throws[32];

	score_board() {
		id = -1; score = -1;
		for(int i = 0; i < 32; i++) {
			frames[i] = -1;
			throws[i] = -1;
		}
	}

	int set_score() {
		if(score != -1)
			return score;
		score = 0;

		for(int f = 0; f < 10; f++) {
			score += max(0, throws[frames[f*2]]) + max(0, throws[frames[f*2 + 1]]);
			if(max(0, throws[frames[f*2]]) == 10) {
				score += max(0, throws[frames[f*2] + 1]) + max(0, throws[frames[f*2] + 2]);
			}
			else if(max(0, throws[frames[f*2]]) + max(0, throws[frames[f*2 + 1]]) == 10) {
				score += max(0, throws[frames[f*2 + 1] + 1]);
			}
		}

		return score;
	}

	bool operator<(const score_board& b) const {
		if(score == b.score)
			return id > b.id;
		return score < b.score;
	}
};

istream& operator>>(istream& istr, score_board& sb) {
	string s;
	int count = 0;
	istr >> sb.id;
	getline(istr, s);
	stringstream sstr(s);
	
	int n = 0;
	int frame_count = 0;
	int throw_count = 0;
	int pin = 0;
	while(sstr >> sb.throws[n]) {
		pin += sb.throws[n];
		sb.frames[frame_count * 2 + throw_count] = n;
		if(pin == 10 || (throw_count > 0 && frame_count < 9)) {
			pin = 0;
			throw_count = 0;
			frame_count++;
		}
		else
			throw_count++;
		n++;
	}
	sb.set_score();

	/*
	cout << "id:" << sb.id << endl;
	for(int i = 0; i < 10; i++) {
		cout << ":" << sb.throws[sb.frames[i*2]] << " " << sb.throws[sb.frames[i*2 + 1]];
	}
	cout << endl;
	*/

	return istr;
}

int main() {
	int n;
	while(cin >> n, n) {
		vector<score_board> in;
		for(int i = 0; i < n; i++) {
			score_board tmp;
			cin >> tmp;
			in.push_back(tmp);
		}
		sort(in.rbegin(), in.rend());
		for(int i = 0; i < in.size(); i++) {
			cout << in[i].id << " " << in[i].score << endl;
		}
	}
	return 0;
}