#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

bool exist[10000][301];

int main(){
	
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < 10000; i++){
			for(int j = 0; j < 301; j++){
				exist[i][j] = false;
			}
		}
		int id, score, round, round_small, dummy, rest;
		bool strike1, strike2, spare;
		bool last_throw;
		
		for(int loop = 0; loop < n; loop++){
			cin >> id;
			round = 1;
			round_small = 1;
			rest = 10;
			score = 0;
			strike1 = false;
			strike2 = false;
			spare = false;
			last_throw = false;
			
			while(true){
				if(round <= 9){
					cin >> dummy;
					score += dummy;
					if(strike1){
						score += dummy;
					}
					if(strike2){
						score += dummy;
					}
					if(spare){
						score += dummy;
						spare = false;
					}
					strike2 = strike1;
					strike1 = false;
					if(rest == dummy){
						if(dummy == 10){
							strike1 = true;
						}else{
							spare = true;
						}
						round++;
						round_small = 1;
						rest = 10;
					}else{
						round_small++;
						rest -= dummy;
						if(round_small >= 3){
							round_small = 1;
							round++;
							rest = 10;
						}
					}
				}else if(round == 10){
					cin >> dummy;
					score += dummy;
					if(strike1){
						score += dummy;
					}
					if(strike2){
						score += dummy;
					}
					if(spare){
						score += dummy;
						spare = false;
					}
					strike2 = strike1;
					strike1 = false;
					if(rest == dummy){
						last_throw = true;
						round_small++;
					}else{
						round_small++;
						rest -= dummy;
					}
					if(round_small >= 3){
						if(last_throw){
							cin >> dummy;
							score += dummy;
						}
						break;
					}
				}
				if(dummy > 10){
					while(true){
					}
				}
				//cout << "round_next = " << round << " : rest_next = " << rest << ", score = " << score << endl;
			}
			exist[id][score] = true;
		}
		for(int i = 300; i >= 0; i--){
			for(int j = 0; j < 10000; j++){
				if(exist[j][i]){
					cout << j << " " << i << endl;
				}
			}
		}
	}
	return 0;
}