#include<iostream>
#include<cstdio>
#include<string>
#define INITIAL 0
using namespace std;
struct comewith {
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 (void){
comewith result[40]={INITIAL};
int m,grad=INITIAL,s=INITIAL,o=INITIAL, h[1/* ← ID */+21],hc[22],b=INITIAL;
        scanf("%d\n",&m);
        for (int i=0;i<m;i++){
                scanf ("%d",&h[0]);  //ID input
   for (int sc=1;sc<=21;sc=sc+2){
    scanf ("%d",&h[sc]);
    if (h[sc]<10){
     scanf ("%d",&h[sc+1]);
    }
    else {
     h[sc+1]=0;
    }
    if (sc==21&&h[sc-1]+h[sc-2]==10){
     scanf ("%d",&h[sc]);
    }
    else {
     h[sc]=0;
    }
                        }
   for (int sc=0;sc<=21;sc++){
    if (h[sc]!=0){
     hc[b]=h[sc];
     b++;
    }
   }
                        int ret=BOWLINGSCORE(h);
                            result[grad].ID=h[INITIAL];
                            result[grad].SCORE=ret;
                            grad++;
        }
        for (int i=0;i<m;i++){
                for (int j=i+1;j<m;j++){
                        if (result[i].SCORE<result[j].SCORE){
                                comewith tmp=result[i];
                                    result[i]=result[j];
                                    result[j]=tmp;
                        }
                }
        }
        while (1){
                if (s>m){
                        if (o==0){
                                break;
                        }
                        s=0;
                        }
                if (result[s].SCORE==result[s+1].SCORE){
                        if(result[s].ID>result[s+1].ID){
                                int tmp=result[s].ID;
                                    result[s].ID=result[s+1].ID;
                                    result[s+1].ID=tmp;
                                    o++;
                        }
                }
        s++;
        }
        for (int i=0;i<m;i++){
                cout<<result[i].ID<<" "<<result[i].SCORE<<endl;
        }
return 0;
}
