//17
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>

using namespace std;

struct IS{
  int i,s;
  bool operator<(IS a)const{
    if(s!=a.s){
      return s>a.s;
    }else{
      return i<a.i;
    }
  }
};

int main(){
  for(int m;cin>>m,m;){
    IS sc[40];
    cin.ignore();
    for(int i=0;i<m;i++){
      string s;
      getline(cin,s);
      stringstream ss(s);
      int id;
      ss>>id;
      int a[21]={};
      for(int i=0;ss>>a[i];i++);
      int scr=0;
      int x=0;
      for(int f=1;;f++){
	if(f!=10){
	  if(a[x]==10){
	    scr+=10+a[x+1]+a[x+2];
	    x++;
	  }else if(a[x]+a[x+1]==10){
	    scr+=10+a[x+2];
	    x+=2;
	  }else{
	    scr+=a[x]+a[x+1];
	    x+=2;
	  }
	}else{
	  scr+=a[x]+a[x+1]+a[x+2];
	  break;
	}
      }
      IS cs={id,scr};
      sc[i]=cs;
    }
    sort(sc,sc+m);
    for(int i=0;i<m;i++){
      cout<<sc[i].i<<' '<<sc[i].s<<endl;
    }
  }
  return 0;
}