#include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

bool cmp(const pair<int,int> &a,const pair<int,int> &b){
    return a.second < b.second;
}

void solve(vector<vector<int> > v){
    map<int,int> point2num;
    vector<pair<int,int> > points;
    for(int i=0;i<v.size();i++){
        int num = v[i][0];
        vector<int> frame(11);
        frame[0] = 0;
        int f=1;int j=1;
        while(true){
            if(f==11)break;
            int x = v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1]+v[i][j+2];
                f++;j++;
                continue;
            }
            j++;
            x = x+v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1];
                f++;j++;
                continue;
            }
            frame[f] = x;
            f++;j++;
            continue;
        }
        int p=0;
        for(int j=0;j<frame.size();j++){
            p+=frame[j];
        }
        points.push_back(make_pair(num,p));
    }
    sort(points.begin(),points.end());
    reverse(points.begin(),points.end());
    stable_sort(points.begin(),points.end(),cmp);
    reverse(points.begin(),points.end());
    for(int i=0;i<points.size();i++){
        cout << points[i].first << " " << points[i].second << endl;
    }
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        cin.ignore();
        vector<vector<int> > v(n);
        for(int i=0;i<n;i++){
            string s;
            getline(cin,s);
            istringstream is(s);
            int x;
            while(is >> x){
                v[i].push_back(x);
            }
        }
        solve(v);
    }
}