#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
typedef struct{
  int no,ptpt;
}P;
using namespace std;
int main(){
  string str;
  int n,cnt,score[21],s;

  while(1){
    cin >> n;
    if(n==0)break;
    P p[n];
    for(int l=0;l<n;l++){
      memset(score,0,sizeof(score));
      cin >> p[l].no;
      for(int i=0;i<18;i+=2){
	cin >> s;
	score[i] = s;
	if(s != 10){
	  cin >> s;
	  score[i+1]=s;
	}
      }
      cin >> score[18] >> score[19];
      if(score[18]+score[19]==10 || score[18]==10 || score[19]==10){
	cin >> s;
	score[20] = s;
      }
      int sum=0;
      for(int i=0;i<18;i+=2){
	if(score[i]==10){ //ストライク
	  sum += ((score[i+2]!=10||i==16) ? 10+score[i+2]+score[i+3] :
		  20+score[i+4]);
	} else if(score[i]+score[i+1]==10){ //スペア
	  sum += 10+score[i+2];
	}else 
	sum += score[i]+score[i+1];
      }
      p[l].ptpt = sum + score[18]+score[19]+score[20];
    }

    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(p[j].ptpt>p[j-1].ptpt){
	  swap(p[j],p[j-1]);
	}
      }
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(p[j].ptpt==p[j-1].ptpt&&p[j].no<p[j-1].no){
	  swap(p[j],p[j-1]);
	}
      }
    }
    for(int i=0;i<n;i++){
      cout << p[i].no << " " << p[i].ptpt << endl;
    }
  }   
}