#include<iostream>
using namespace std;
int main(){
long n,i,j,s[40],p[21],q[40],t;
while(cin>>n,n){
for(i=0;i<n;i++){
cin>>s[i];
q[i]=0;
for(j=0;j<20;j++){
cin>>p[j];
q[i]+=p[j];
if(j<18&&j%2==0&&p[j]==10){j++;p[j]=0;}
}
if(p[18]==10||p[18]+p[19]==10){cin>>p[20];q[i]+=p[j];}
for(j=0;j<18;j+=2){
if(p[j]==10){
if(p[j+2]==10)q[i]+=p[j+2]+p[j+4];
else q[i]+=p[j+2]+p[j+3];
}else if(p[j]+p[j+1]==10){
q[i]+=p[j+2];
}
}
}
for(i=n-1;i>=1;i--){
for(j=0;j<i;j++){
if(q[j]<q[j+1]||q[j]==q[j+1]&&s[j]>s[j+1]){
t=q[j];q[j]=q[j+1];q[j+1]=t;
t=s[j];s[j]=s[j+1];s[j+1]=t;
}
}
}
for(i=0;i<n;i++){
cout<<" "<<s[i]<<" "<<q[i]<<endl;
}
}
return 0;
}