
import std.stdio, std.conv, std.string, std.algorithm, std.array;

int calc_point(int[] arr) {
  int i = 0;
  int[11] point;
  int strike = 0;
  int game = 1;
  while(game <= 10) {
    if (arr[i] == 10) {
      point[game] += 10 + arr[i + 1] + arr[i + 2];
      i += 1;
    }
    else {
      if (strike > 0) {
        int p = (arr[i] + arr[i + 1]);
        point[game - 1] += p;
        strike = 0;
      }
      
      if ((arr[i] + arr[i + 1]) == 10) {
        point[game] += 10 + arr[i + 2];
      }
      else {
        point[game] += (arr[i] + arr[i + 1]);
      }
      i += 2;
    }
    game += 1;
  }
  return point.reduce!("a + b");
}

void main() {
  for(int t; readf("%d\n", &t), t != 0;) {
    int[][int] people;
    foreach(i; 0..t) {
      int[] line = readln.chomp.split(" ").map!(to!(int)).array;
      people[line[1..$].calc_point] ~= line[0];
    }
    int[] keys = sort!("a > b")(people.keys).array;
    foreach(point; keys) {
      int[] ordered = sort!("a < b")(people[point]).array;
      foreach(id; ordered) {
        writeln(id, " ", point);
      }
    }    
  }
}