#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int m;
    cin >> m;

    if(m == 0) break;

    vector<pii> ans;

    REP(i,m){
      int id;
      cin >> id;

      int point[23] = {};
      REP(i,23){
        point[i] = -1;
      }

      int game = 0;
      while(game != 9){
        int tmp;
        int pin = 10;

        cin >> tmp;
        pin -= tmp;

        //strikeの時
        if(pin == 0){
          point[game*2] = 10;
          game++;
          continue;
        }

        point[game*2] = tmp;

        cin >> tmp;
        pin -= tmp;

        point[game*2+1] = tmp;

        game++;
      }

      //game = 10
      int tmp;
      int cnt = 0;

      cin >> tmp;
      point[game*2] = tmp;
      cnt += tmp;

      cin >> tmp;
      cnt += tmp;
      point[game*2+1] = tmp;

      if(cnt >= 10){
        cin >> tmp;
        point[game*2+2] = tmp;
      }

      //点数計算
      int sum = 0;
      REP(i,9){
        //stike
        if(point[i*2] == 10){
          if(point[(i+1)*2] == 10){
            if(i == 8){
              sum += 10 + 10 + point[(i+1)*2+1];
            }else{
              sum += 10 + 10 + point[(i+2)*2];
            }
          }else{
            sum += 10 + point[(i+1)*2] + point[(i+1)*2+1];
          }
          //spare
        }else if(point[i*2] + point[i*2+1] == 10){
          sum += point[i*2] + point[i*2+1] + point[(i+1)*2];
        }else{
          sum += point[i*2] + point[i*2+1];
        }

      //cout << sum << endl;
      }

      sum += point[9*2] + point[9*2+1] + max(0, point[9*2+2]);
      //cout << sum << endl;
      ans.pb(MP(-sum, id));
    }
    SORTV(ans);
    REPI(itr, ans){
      cout << itr->second << " " << itr->first * -1 << endl;
    }
  }
  return 0;
}


