#include<iostream>
#include<algorithm>
#include<vector>

#define FRAMES 10
#define SCORES 21

using namespace std;
class Student{
public:
	Student(){
		id = 0;
		for(int i = 0; i < SCORES; ++i){
			scores[i] = 0;
		}
	}
	int id;
	int scores[SCORES];
	void calculateScore(){
		int nScore = 0;
		int frame = 0;
		for(int i = 0; i < SCORES; ++frame){
			if( frame != FRAMES-1 ){
				int a = scores[ i ];
				int b = scores[ i + 1 ];
				if( a == 10 ){
					nScore += a + b + scores[ i + 2 ];
					++i;
				}else if( a + b == 10 ){
					nScore += a + b + scores[ i + 2 ];
					i+=2;
				}else{
					nScore += a + b;
					i+=2;
				}
			}else{
				nScore += scores[ i ] + scores[ i + 1 ] + scores[ i + 2 ];
				break;
			}
		}
		score = nScore;
	}
	int score;
};
bool operator < ( const Student &t1, const Student &t2 ){
	if( t1.score == t2.score ){
		return t1.id < t2.id;
	}else
		return t1.score > t2.score;
}
istream & operator >> (istream &is, Student &std){
	int i = 0;
	is >> std.id;
	while( true ){
		is >> std.scores[i++];
		if( is.get() == '\n' )
			break;
	}
	return is;
}
ostream & operator << (ostream &os, Student &std){
	os << std.id << ' ' << std.score;
	return os;
}

int main()
{

	while( true ){
		int n;
		vector< Student > vStudents;
		cin >> n;
		if( n == 0 ) break;
		for(int i = 0; i < n; ++i){
			Student t;
			cin >> t;
			t.calculateScore();
			vStudents.push_back( t );
		}
		sort( vStudents.begin() , vStudents.end() );
		for(int i = 0; i < n; ++i){
			cout << vStudents[i] << '\n';
		}
	}
	return 0;
}