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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

struct hoge {
  int id;
  int score;
  hoge(int id, int score) : id(id), score(score) {}
};
bool operator<(const hoge &a, const hoge &b) {
  return (a.score != b.score)? a.score > b.score : a.id < b.id;
}

int main() {
  int n;
  while(cin >> n, n) {
    cin.ignore();
    vector<hoge> w;
    while(n--) {
      stringstream ss;
      string s;
      getline(cin, s);
      ss << s;
      int id;
      ss >> id;
      int a;
      vector<int> v;
      while(ss >> a)
        v.push_back(a);
      int vn = v.size();

      int frame = 0;
      int cnt = 0;
      int score = 0;
      int i=0;
      while(frame < 9) {
        if (cnt == 0) {
          if (v[i] == 10) {
            score += 10 + v[i+1] + v[i+2];
          } else {
            cnt++;
          }
        } else {
          int tmp = v[i-1] + v[i];
          score += tmp;
          if (tmp == 10) {
            score += v[i+1];
          }
          cnt = 0;
        }
        if (cnt == 0)
          frame++;
        
        i++;
      }
      int tmp = v[i] + v[i+1];
      score += tmp;
      if (tmp >= 10) {
        score += v[i+2];
      }
      w.push_back(hoge(id, score));
    }
    sort(ALL(w));
    FOR(it,w) {
      printf("%d %d\n",(*it).id,(*it).score);
    }
  }
}