// 2011/02/27 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct player{
	int num;
	int sco;
};

int main()
{
	while(true){
		string str;
		getline(cin, str);
		istringstream ist(str);
		int m;
		ist >> m;
		if(m==0)
			break;

		struct player ply[40];
		for(int i=0; i<m; i++){
			getline(cin, str);
			istringstream ist2(str);

			ist2 >> ply[i].num;
			int pin[21];
			for(int j=0; ist2 >> pin[j]; j++)
				;

			ply[i].sco = 0;
			int k = 0;
			for(int j=1; j<=9; j++){
				ply[i].sco += pin[k++];
				if(pin[k-1]==10){
					ply[i].sco += (pin[k]+pin[k+1]);
					continue;
				}
				ply[i].sco += pin[k++];
				if(pin[k-2]+pin[k-1]==10){
					ply[i].sco += pin[k];
					continue;
				}
			}
			ply[i].sco += pin[k++];
			ply[i].sco += pin[k++];
			if(pin[k-2]==10||pin[k-2]+pin[k-1]==10)
				ply[i].sco += pin[k];

		}

		for(int i=0; i<m-1; i++)
			for(int j=i+1; j<m; j++)
				if(ply[i].sco<ply[j].sco){
					struct player tmp = ply[i];
					ply[i] = ply[j];
					ply[j] = tmp;
				}

		for(int i=0; i<m; i++)
			cout << ply[i].num << ' ' << ply[i].sco << endl;
	}

	return 0;
}