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

struct Data{int player,score;};
bool operator<(Data a,Data b){return a.score!=b.score?a.score>b.score:a.player<b.player;}

int main()
{
  int n,player,score[21];
  int i;
  int frame,sum;
  vector<Data> result;
  vector<Data>::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];
      Data d={player,sum};
      result.push_back(d);
    }

    sort(result.begin(),result.end());
    for(it=result.begin();it!=result.end();it++)
      cout<<(*it).player<<" "<<(*it).score<<endl;
  }
}