#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<int, int> P;
 
P data[40];
int cnt[11];
int main(){
  int m, a, b, c, score;
  while(cin >> m && m){
    rep(i, m){
      score = 0;
 
      fill(cnt, cnt + 10, 0);
      cin >> data[i].second;
      rep(j, 10){
    cin >> a;
    score += a;
    rep(k, 10) if(cnt[k] > 0){
      cnt[k]--;
      score += a;
    }
 
    if(a == 10){
 
      if(j != 9)cnt[j]+=2;
      else{
        cin >> b >> c;
        score += b + c;
        rep(k, 10)if(cnt[k]){
          cnt[k]--;
          score += b;
        }
      }
       
    }else{
 
      cin >> b;
      score += b;
      rep(k, 10) if(cnt[k] > 0){
        cnt[k]--;
        score += b;
      }
      if(a + b == 10){
        if(j != 9)cnt[j]++;
        else{
          cin >> c;
          score += c;
        }
      }
    }
      }
      data[i].first = -score;
    }
    sort(data, data + m);
    rep(i, m){
      cout << data[i].second << " " << -data[i].first << endl;
    }
  }
  return 0;
}