#include <bits/stdc++.h>

using namespace std;

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

int main()
{
  int m;
  while(cin >> m, m){
    PART p[40];
    for(int i = 0; i < m; i++){
      cin >> p[i].id;
      p[i].score = 0;
      int ext = 0;
      int frame = 0;
      bool flag = false;
      while(1){
	int pin = 0;
	for(int k = 0; k < 2 && pin < 10; k++){
	  int x;
	  cin >> x;
	  pin += x;
	  p[i].score += x;
	  if(ext > 0) p[i].score += x, ext--;
	  if(flag) p[i].score += x, flag = false;
	  if(k == 0 && pin == 10){
	    if(ext > 0) ext += 1, flag = true;
	    else ext += 2, flag = false;
	  }
	  else if(k == 1 && pin == 10) ext += 1;
	}
	if(frame == 9 && ext > 0){
	  while(ext--){
	    int x;
	    cin >> x;
	    if(flag) p[i].score += x, flag = false;
	    p[i].score += x;
	  }
	}
	frame++;
	if(frame == 10) break;
      }
    }
    sort(p, p + m);
    for(int i = 0; i < m; i++){
      cout << p[i].id << " " << p[i].score << endl;
    }
  }
  return 0;
}