#include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
using namespace std;


int main(void){
	int n;
	while(cin>>n){
		if(n==0)break;
	multimap< int ,int,greater<int> > ans;
	int number;
	while(n--)
	{
		int score[30]={0},sum=0;
		cin>>number;
		
		for(int i=0; i<21; ++i){	
			cin>>score[i];
			if(score[i]==10 && i<18) i+=1;
			if(i==19 && score[18]+score[19]<10)break;
		}

		for(int i=0; i<21; ++i)
		{
			if( score[i]==10 && i<18 )
			{
				sum += 10;
				sum += score[i+2] + score[i+3];
				if(score[i+2]==10) sum += score[i+4];
				++i;
			}
			else if( i%2==1 && score[i-1]+score[i]==10 && i<18)
			{
				sum += score[i+1];
			}
			if( i==18 ){
				if( score[18] + score[19] == 10)
					sum += score[18]+score[19]+score[20];
				else
					sum += score[18]+score[19];
				break;
			}
			sum += score[i];
		}
		ans.insert( make_pair( sum,number ) );
	}
	multimap< int , int,greater<int> >::iterator it = ans.begin();
	while( it != ans.end() )
	{
		cout << (*it).second << " " << (*it).first << endl;
		++it;
	}
	}
	return 0;
}