// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

template<class Istr>
vector<int> separated_str(Istr& istr, char delim){
    std::string str;
    vector<int> res;
    while(std::getline(istr, str, delim)){
        res.push_back(stoi(str));
    }
    return res;
}

signed main() {
    int M;
    while(cin >> M, M) {
        vector<int> ids, scores, ord;
        string s;
        cin.ignore();
        for(int i=0; i<M; i++) {
            getline(cin, s);
            stringstream ss(s);
            auto v = separated_str(ss, ' ');

            int id = v[0];
            int score = 0, pre1 = 0, pre2 = 0, t = 1, p = 0, f = 1;
            for(size_t k=1; k<v.size(); k++) {
                score += v[k];
                score += (pre1 + pre2) * v[k];

                pre1 = pre2;
                pre2 = 0;
                int pf = f, pt = t;
                if(t == 1 and v[k] == 10) {
                    if(f < 10) pre2++;
                    t = 1;
                    f++;
                }
                else if(t == 2 and p + v[k] == 10) {
                    if(f < 10) pre1++;
                    t = 1;
                    f++;
                }
                else {
                    t++;
                    if(f < 10 and t == 3) f++, t = 1;
                }
                p = v[k];
                // fprintf(stderr, "# f = %lld, t = %lld, %lld\n", pf, pt, score);
            }
            ids.push_back(id);
            scores.push_back(score);
            ord.push_back(i);
        }
        sort(ord.begin(), ord.end(), [&](int x, int y) {
                if(scores[x] != scores[y]) return scores[x] > scores[y];
                return ids[x] < ids[y];
            });

        for(int i=0; i<M; i++) {
            cout << ids[ ord[i] ] << " " << scores[ ord[i] ] << endl;
        }
    }
    return 0;
}

