#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int meibo[10010],st[10100][20],sp[10100][20],score[10100];

int main(){
  while(true){//game
    int a;
    cin>>a;
    if(a==0){break;}
    a++;
    for(int i=0;i<10001;i++){
      meibo[i]=score[i]=0;
      for(int j=0;j<11;j++){
	st[i][j]=sp[i][j]=0;
      }
    }
    for(int i=1;i<a;i++){
      cin>>meibo[i];
      for(int j=1;j<11;j++){
	int be=0,af=0;
	cin>>be;
	if(j>2&&st[meibo[i]][j-2]>0){
	  score[meibo[i]]+=be;
	  st[meibo[i]][j-2]--;
	}
	if(j>1&&st[meibo[i]][j-1]>0){
	  score[meibo[i]]+=be;
	  st[meibo[i]][j-1]--;
	}
	if(j>1&&sp[meibo[i]][j-1]>0){
	  score[meibo[i]]+=be;
	  sp[meibo[i]][j-1]--;
	}
	if(be==10){st[meibo[i]][j]=2;}
	else{
	  cin>>af;
	  if((be+af)==10){sp[meibo[i]][j]=1;}
	  if(j>1&&st[meibo[i]][j-1]>0){
	    score[meibo[i]]+=af;
	    st[meibo[i]][j-1]--;
	  }
	  if(j==10&&be+af>=10){
	    int cn;cin>>cn;
	    score[meibo[i]]+=cn;
	  }
	}
	if(j==10&&be==10){
	  cin>>af;
	  if((be+af)==10){sp[meibo[i]][j]=1;}
	  if(j>1&&st[meibo[i]][j-1]>0){
	    score[meibo[i]]+=af;
	    st[meibo[i]][j-1]--;
	  }
	  int cn;cin>>cn;
	  score[meibo[i]]+=cn;
	}
	score[meibo[i]]=score[meibo[i]]+be+af;
      }
    }
    int l=1;
    while(l < a){
      for(int i=1;i<a;i++){
	int ext=0;
	for(int j=1;j<a;j++){
	  if(score[meibo[i]]<score[meibo[j]]){
	    ext++;
	  }
	}
	if(ext==0){
	  cout<<meibo[i]<<" "<<score[meibo[i]]<<endl;
	  score[meibo[i]]=0;
	  break;
	}
      }
      l++;
    }
  }///game
}