#include <iostream>
#include <set>
using namespace std;

class Student{
public:
  int score, no;
  Student() : score(0) {}
  bool operator <(const Student &s) const{
    if(score != s.score) return score > s.score;
    return no < s.no;
  }
};

main() {
  while(1) {
    int m;
    set<Student> S;
    cin >> m;
    if(m == 0) break;
    for(int i = 0; i < m; i++) {
      int result[10];
      Student tmp;
      int a, b, c;
      cin >> tmp.no;
      for(int i = 0; i < 9; i++) {
	cin >> a;
	tmp.score += a;
	if(i-1 >= 0 && result[i-1] >= 1) tmp.score += a;
	if(i-2 >= 0 && result[i-2] == 2 && result[i-1] == 2) tmp.score += a;

	if(a == 10) {
	  result[i] = 2;
	  continue;
	}
	cin >> b;
	tmp.score += b;
	if(i-1 >= 0 && result[i-1] == 2) tmp.score += b;
	if(a+b == 10) {
	  result[i] = 1;
	  continue;
	}
	result[i] = 0;
      }

      cin >> a >> b;
      c = 0;
      if(a+b >= 10) {
	cin >> c;
      }
      if(result[8] >= 1) tmp.score += a;
      if(result[7] == 2 && result[8] == 2) tmp.score += a;
      if(result[8] == 2) tmp.score += b;
      tmp.score += a+b+c;

      S.insert(tmp);
    }
    for(set<Student>::iterator it = S.begin();
	it != S.end(); it++) {
      cout << it->no << ' ' << it->score << endl;
    }
  }
}