#include<bits/stdc++.h>
using namespace std;
 
unordered_map<int, int>U;
vector<int>r;
vector<int>bunkatu(string a) {
    a += " ";
    vector<int>V;
    string b;
    for (char c : a) {
        if (c == ' ') { V.push_back(stoi(b)); b = ""; }
        else b += c;
    }
    return V;
}
int main(){
    int a;
    while (cin >> a, a) {
        U.clear();
        r.clear();
        for (int l = 0; l < a; l++) {
            int n; cin >> n;
            r.push_back(n);
            string b; getline(cin, b);
            b = b.substr(1, b.length() - 1);
            vector<int>V = bunkatu(b);
            int now = 0;
            int sum = 0;
            for (int i = 0; i < 10; i++) {
                if (V[now] == 10) {
                    sum += 10 + V[now+1] + V[now+2];
                    now++;
                    continue;
                }
                int k = V[now] + V[now + 1];
                if (k == 10)k += V[now + 2];
                sum += k;
                now += 2;
            }
            U[n]= sum;
        }
        sort(r.begin(),r.end(), [](int a, int b) {if (U[a] != U[b])return U[a] > U[b]; return a < b; });
        for (int i = 0; i < a; i++) {
            cout << r[i] << " " << U[r[i]] << endl;
        }
    }
}