#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		int id;
		vector<P> vec;
		for(int ii = 0;ii < n;ii++){
			int add[21] = {},score[21] = {},sum = 0,frame = 0,tou = 1;
			cin >> id;
			for(int i = 0;frame < 10;i++){
				cin >> score[i];
				//cout << score[i] << " " << frame << " " << tou << endl;
				add[i]++;
				if(tou == 1 && score[i] == 10){
					if(frame != 9){
						frame++;
						add[i + 1]++;
						add[i + 2]++;
					}else{
						tou++;
					}
				}else if(tou == 2 && score[i] + score[i - 1] >= 10){
					if(frame == 9) tou = 3;
					else{
						frame++;
						add[i + 1]++;
						tou = 1;
					}
				}else if(tou == 2){
					frame++;
					tou = 1;
				}else if(tou == 3) frame++;
				else tou++;
			}
			for(int i = 0;i < 21;i++){
				sum += score[i] * add[i];
			}
			vec.push_back(P(sum,-id));
		}
		sort(vec.begin(),vec.end(),greater<P>());
		for(int i = 0;i < n;i++){
			cout << -vec[i].second << " " << vec[i].first << endl;
		}
	}
	return 0;
}