#include <iostream>
#include <cstdio>
#define INITIAL 0
using namespace std;
struct IDSCORE {
int ID;
int SCORE;
};
int BOWLINGSCORE(int h[22]){
int NEXT=INITIAL,total=INITIAL;
if (h[1]<10){    //1
    total+=h[1]+h[2];
    if (h[1]+h[2]==10){
        total+=h[3];
    }
NEXT=3;
}
else {
    total+=h[1]+h[2]+h[3];
    NEXT=2;
}
if (h[NEXT]<10){ //2
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //3
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //4
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //5
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //6
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //7
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //8
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //9
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //10
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
}
return total;
}
int main (){
IDSCORE ret[64];
int m,n[1+21],ct[1+21],b=0,s=0,o=0;
while (1){
cin>>m;
if (m==0)break;
///////////////////////////////////////////////////////
for (int i=0;i<m;i++){
    for (int zzz=0;zzz<22;zzz++){
        n[zzz]=0;
        ct[zzz]=0;
    }
    b=0;
    s=0;
    o=0;
    cin>>n[0]; //score
    for (int j=1;j<19;j=j+2){
        cin>>n[j];
        if (n[j]==10) n[j+1]=11;
        else cin>>n[j+1];
    }
    cin>>n[19];
    cin>>n[20];
    if (n[19]+n[20]>=10)cin>>n[21];

    for (int j=0;j<22;j++){
        if (n[j]!=11){
            ct[b]=n[j];
            b++;
        }
    }

ret[i].SCORE=BOWLINGSCORE(ct);
ret[i].ID=n[0];
}
//////////////////////////////////////////////////////
for (int i=0;i<m-1;i++){
    for (int j=i+1;j<m;j++){
        if (ret[i].SCORE<ret[j].SCORE){
        IDSCORE temp=ret[i];
        ret[i]=ret[j];
        ret[j]=temp;
        }
    }
}
while (1){
    if (s==m+1){
        s=0;
        if (o==0)break;
        else o=0;
    }
if (ret[s].SCORE==ret[s+1].SCORE&&ret[s].ID>ret[s+1].ID){
    IDSCORE temp=ret[s];
    ret[s]=ret[s+1];
    ret[s+1]=temp;
    o++;
}
s++;
}
for (int i=0;i<m;i++){
    cout<<ret[i].ID<<" "<<ret[i].SCORE<<endl;
}
}
return 0;
}



Measured memory_bytes: 2980