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

struct Player
{
	Player( int score, int id ) : first( score ), second( id ){}
	int first;
	int second;
	bool operator<( const Player& p ) const
	{
		if( this->first > p.first ) return true;
		if( this->first < p.first ) return false;
		if( this->second < p.second ) return true;
		return false;
	}
};

int main()
{
	int n;

	while( cin >>n && n ){
		vector< Player > playerList;

		for( int i = 0; i < n; ++i ){
			int id;

			cin >> id;

			vector< pair< int, int > > throwResult;
			vector< pair< int, int > > scoreBoard;
			int frame = 0;
			int prevPin = 0;
			int throwCount = 0;
			while( frame < 10 - 1 ){
				int pin;
				cin >> pin;
				throwResult.push_back( make_pair( frame, pin ) );

				if( throwCount == 0 ){
					if( pin == 10 ){
						scoreBoard.push_back( make_pair( 10, 2 ) );
						++frame;
					}else{
						prevPin = pin;
						++throwCount;
					}
				}else{
					pin += prevPin;
					prevPin = 0;
					throwCount = 0;
					int state = pin == 10 ? 1 : 0;
					scoreBoard.push_back( make_pair( pin, state ) );
					++frame;
				}
			}
			throwCount = 0;
			prevPin = 0;
			while( throwCount < 3 ){
				int pin;
				cin >> pin;
				throwResult.push_back( make_pair( frame, pin ) );

				prevPin += pin;
				if( throwCount == 1 && prevPin < 10 ){
					break;
				}
				++throwCount;
			}
			scoreBoard.push_back( make_pair( prevPin, 0 ) );

			int score = 0;
			vector< pair< int, int > >::iterator itr = throwResult.begin();
			for( int j = 0; j < 10; ++j ){
				int sc = scoreBoard[ j ].first;
				int st = scoreBoard[ j ].second;
				if( st > 0 ){
					while( itr != throwResult.end() && itr->first <= j ){
						++itr;
					}
					vector< pair< int, int > >::iterator itr2 = itr;
					for( int k = 0; k < st; ++k, ++itr2 ){
						sc += itr2->second;
					}
				}
				score += sc;
			}
			playerList.push_back( Player( score, id ) );
		}
		sort( playerList.begin(), playerList.end() );

		for( int i = 0; i < n; ++i ){
			cout << playerList[ i ].second << " " << playerList[ i ].first << endl;
		}
	}

	return 0;
}