#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <utility>
#include <algorithm>
#include <numeric>

int calc(std::vector<int> const& pts) {
  std::vector<std::vector<int>> frame(10);
  {
    size_t i = 0;
    for (int p: pts) {
      frame[i].push_back(p);
      if (i < 9) {
        if (frame[i].size() == 2) {
          ++i;
        } else if (std::accumulate(frame[i].begin(), frame[i].end(), 0) == 10) {
          ++i;
        }
      }
    }
  }
  std::vector<int> framescore(10);
  for (size_t i = 0; i < 9; ++i) {
    framescore[i] = std::accumulate(frame[i].begin(), frame[i].end(), 0);
    if (framescore[i] == 10) {
      if (frame[i].size() == 1) {
        // strike
        framescore[i] += frame[i+1][0];
        if (frame[i+1].size() > 1) {
          framescore[i] += frame[i+1][1];
        } else {
          framescore[i] += frame[i+2][0];
        }
      } else {
        assert(frame[i].size() == 2);
        // spare
        framescore[i] += frame[i+1][0];
      }
    }
  }
  framescore[9] = std::accumulate(frame[9].begin(), frame[9].end(), 0);
  return std::accumulate(framescore.begin(), framescore.end(), 0);
}

int testcase_ends() {
  size_t m;
  scanf("%zu", &m);
  if (m == 0) return 1;

  std::vector<std::pair<int, int>> ss(m);
  for (size_t i = 0; i < m; ++i) {
    int id;
    scanf("%d", &id);

    char buf[1024];
    fgets(buf, sizeof buf, stdin);
    char* pos = buf;
    std::vector<int> pts;
    while (true) {
      char* endpos;
      int x = strtol(pos, &endpos, 10);
      if (endpos == pos) break;
      pos = endpos;
      pts.push_back(x);
    }
    // for (size_t j = 0; j < ss[i].second.size(); ++j)
    //   fprintf(stderr, "%d%c", ss[i].second[j], j+1<ss[i].second.size()? ' ':'\n');

    ss[i].first = -calc(pts);
    ss[i].second = id;
  }
  std::sort(ss.begin(), ss.end());
  for (auto const& si: ss)
    printf("%d %d\n", si.second, -si.first);

  return 0;
}

int main() {
  while (!testcase_ends()) {
  }
}

