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

int main()
{
  int n,player,score[21];
  int i;
  int frame,sum;
  multimap< int,int,greater<int> > result;
  multimap<int,int>::iterator it;
  string s;
  while(getline(cin,s)){
    stringstream ss(s);
    ss>>n;
    if(!n)break;

    result.clear();
    while(n-->0){
      getline(cin,s);
      stringstream ss(s);
      ss>>player;
      for(i=0;i<21;i++)ss>>score[i];
      i=sum=0;
      frame=1;
      while(frame<=9){
	if(score[i]+score[i+1]<10){
	  sum+=score[i]+score[i+1];
	  i+=2;
	}else if(score[i]==10){
	  sum+=score[i]+score[i+1]+score[i+2];
	  i++;
	}else if(score[i]+score[i+1]==10){
	  sum+=score[i]+score[i+1]+score[i+2];
	  i+=2;
	}
	frame++;
      }
      if(score[i]+score[i+1]<10)sum+=score[i]+score[i+1];
      else if(score[i]==10)sum+=score[i]+score[i+1]+score[i+2];
      else if(score[i]+score[i+1]==10)sum+=score[i]+score[i+1]+score[i+2];
      result.insert(make_pair(sum,player));
    }

    for(it=result.begin();it!=result.end();it++)
      cout<<it->second<<" "<<it->first<<endl;
  }
}