#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i = 0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int ROUND = 10, STR = 2, SP = 1;
typedef pair<int, int> pp;
int main()
{
    int m;
    while(cin >> m && m)
    {
        vector<pp> po;
        rep(k,m)
        {
            int snum, t;
            cin >> snum;

            vector<int> th_pin;
            int fir, sec;
            for(int i_f = 0;i_f < 9; i_f++)
            {
                cin >> fir;
                th_pin.push_back(fir);
                if(fir == 10){ continue;}
                cin >> sec;
                th_pin.push_back(sec);
            }
            cin >> fir;
            if(fir == 10)
            {
                cin >> sec >> t;
                th_pin.push_back(fir); th_pin.push_back(sec);th_pin.push_back(t);
            }
            else
            {
                cin >> sec;
                th_pin.push_back(fir); th_pin.push_back(sec);
                if(fir + sec == 10){cin >>t ; th_pin.push_back(t);}
            }
            //REP(th_pin.size()) cout << i << "th " << th_pin[i] << endl;
            int f_point[10] = {};
            int th = 0;
            for(int i_f = 0;i_f < 10; i_f++)
            {
                if(th_pin[th] == 10)
                    f_point[i_f] = th_pin[th] + th_pin[th+1] + th_pin[th+2];
                else if(th_pin[th] + th_pin[th+1] == 10)
                {
                    f_point[i_f] = th_pin[th] + th_pin[th+1] + th_pin[th+2];
                    th++;
                }
                else
                {
                    f_point[i_f] = th_pin[th] + th_pin[th+1];
                    th++;
                }
                th++;
            }
            int point = 0;
            REP(10) point += f_point[i];
            po.push_back(pp(-point, snum));
        }
        sort(all(po));

        REP(po.size()) cout << po[i].second << " " << -po[i].first << endl;

    }
    return 0;
}