#include<bits/stdc++.h>
using namespace std;

int N;
void solve(){
    vector<pair<int,int> >R;

    while(N--){
        int p;scanf("%d",&p);
        vector<int>V;

        for(int i=0;i<10;i++){
            int a,b;
            scanf("%d",&a);
            V.push_back(a);
            if(a!=10||i==9){
                scanf("%d",&b);
                V.push_back(b);
            }
            if(a+b>=10&&i==9){
                int c;
                scanf("%d",&c);
                V.push_back(c);
            }
        }
        int ans=0,cur=0;
        for(int i=0;i<9;i++){
            ans+=V[cur];
            if(V[cur]==10){
                ans+=V[cur+1]+V[cur+2];
            }
            else{
                cur++;
                ans+=V[cur];
                if(V[cur-1]+V[cur]==10)ans+=V[cur+1];
            }
            cur++;
        }
        while(cur<V.size())ans+=V[cur++];
        R.push_back(pair<int,int>(ans,9999-p));
    }
    sort(R.rbegin(),R.rend());

    for(int i=0;i<R.size();i++)printf("%d %d\n",-(R[i].second-9999),R[i].first);
}

int main(){
    while(scanf("%d",&N),N)solve();
    return 0;
}