#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    while(cin >> n, n){
        cin.ignore();
        vector<pair<int, int> > ans;
        for(int i=0; i< n; i++){
            string ss;
            getline(cin,ss);

            vector<int> v;
            while(true){
                int idx = 0;
                while(ss[idx] != ' ') idx++;
                string num = ss.substr(0, idx);
                v.push_back(stoi(num));
                if(num == ss) break;
                ss = ss.substr(idx+1);
            }
            pair<int, int> p;
            p.second = -1*v[0];
            int score = 0;
            int frame[15] = {0};
            int s[15] = {0};
            int pp[15] = {0};
            int count = 0;
            for(int i=1; i< v.size(); i++){
                if(count < 9){
                    int pin = v[i];
                    if(pin != 10){
                        i++;
                        pin += v[i];
                        if(pin == 10) s[count] = 2;
                        else s[count] = 1;
                        frame[count] = pin;
                    }
                    else {
                        s[count] = 3;
                        frame[count] = pin;
                    }
                } else {
                    int pin = v[i];
                    s[count] = 1;
                    frame[count] = pin;
                }
                pp[count] = i;
                count++;
            }
            for(int i=0; i < 12; i++){
                score += frame[i];
                for(int j=1; j < s[i]; j++){
                    score += v[pp[i]+j];
                }
            }
            p.first = score;
            ans.push_back(p);
        }
        sort(ans.rbegin(), ans.rend());
        for(int i=0; i < ans.size(); i++){
            cout << -ans[i].second << " " << ans[i].first << endl;
        }
    }
}