#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct P {
  int id, score;
  vector<int> pin;
  P() {}
  P(int id, vector<int> pin) : id(id), pin(pin) {
    int game = 0, turn = 0, pz = pin.size(), pos = -1;
    for (int i = 0; i < pz; i++) {
      if (pos < 0 && game == 9) pos = i;
      if (pin[i] == 10 || turn == 1) {
        game++; turn = 0;
      } else {
        turn = 1;
      }
    }
    turn = 0;
    int res = 0;
    for (int i = 0; i < pos; i++) {
      if (turn == 0 && pin[i] == 10) {
        res += pin[i] + pin[i + 1] + pin[i + 2];
        turn = 0;
      } else if (turn == 1 && pin[i - 1] + pin[i] == 10) {
        res += pin[i] + pin[i + 1];
        turn = 0;
      } else {
        res += pin[i];
        turn ^= 1;
      }
    }
    for (int i = pos; i < pz; i++) {
      res += pin[i];
    }
    score = res;
  }
  bool operator < (P other) {
    return score != other.score ? score > other.score : id < other.id;
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int m;
  while (cin >> m, m) {
    cin.ignore();
    vector<P> ps;
    for (int i = 0; i < m; i++) {
      string s;
      getline(cin, s);
      stringstream ss;
      ss << s;
      ss >> s;
      int id = stoi(s);
      vector<int> a;
      while (ss >> s) {
        a.emplace_back(stoi(s));
      }
      ps.emplace_back(P(id, a));
    }
    sort(ps.begin(), ps.end());
    for (int i = 0; i < m; i++) {
      cout << ps[i].id << " " << ps[i].score << endl;
    }
  }

  return 0;
}
