#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){

	int n, score[40], h[21], cnt, frame, p, pre, tmp, index[40], sn[40];
	bool flg;
	
	while(cin >> n){
		if(n == 0) break;
		
		fill(score, score+40, 0);
		for(int i=0; i<40; i++){
			index[i] = i;
		}

		for(int i=0; i<n; i++){
			fill(h, h+21, 1);
			cnt = 0;
			frame = 1;
			flg = false;
			pre = 0;	
		
			cin >> sn[i];
			while(frame<10){
				cin >> p;
				if(flg == false){
					if(p != 10){
						pre = p;
						flg = true;
					}
					else {
						h[cnt+1]++;
						h[cnt+2]++;
						frame++;
					}
				}
				else {
					if(p + pre == 10) h[cnt+1]++;
					flg = false;
					frame++;
				}
				score[i] += p * h[cnt];
				cnt++;
			}
			for(int j=0; j<3; j++){
				cin >> p;
				score[i] += p * h[cnt];
				cnt++;
				if(j == 0) pre = p;
				else if(j == 1 && p + pre < 10) break;
			}
		}
		
		for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(score[index[j]] > score[index[j+1]]){
					tmp = index[j];
					index[j] = index[j+1];
					index[j+1] = tmp;
				}
				else if(score[index[j]] == score[index[j+1]]){
					if(sn[index[j]] < sn[index[j+1]]){
						tmp = index[j];
						index[j] = index[j+1];
						index[j+1] = tmp;
					}
				}
			}
		}
		
		for(int i=n-1; i>=0; i--){
			cout << sn[index[i]] << " " << score[index[i]] << endl;
		}
		
	}

	return 0;
	
}