#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

#define f first
#define s second
typedef pair<int, int> P;

int ID, rec[22];

int split(string s){
  stringstream ss(s);
  int i = 0;
  while(ss >> rec[i]) i++;
  return i;
}

bool compare(const P x, const P y){
  if(x.f == y.f){
    return x.s < y.s;
  }
  return x.f > y.f;
} 

int main(){
  int n;
  while(cin >> n, n){
    vector<P> data;
    string s;

    for(int cs = 0 ; cs < n ; cs++){
      memset(rec, 0, sizeof(rec));
      cin >> ID;
      getline(cin, s);
      int N = split(s);
      int tes = 0;
      int res = 0, flame = 1;
      for(int i = 0 ; flame <= 10 ; flame++, i++){
	res += rec[i] + rec[i+1];
	if(flame > 9) res += rec[i+2];
	else if(rec[i] == 10) res += rec[i+2];
	else{
	  if(rec[i]+rec[i+1] == 10) res += rec[i+2];
	  i++;
	}
      }
      data.push_back(P(res, ID));
    }
    sort(data.begin(), data.end(), compare);
    for(int i = 0 ; i < n ; i++){
      cout << data[i].second << ' ' << data[i].first << endl;
    }
  }
  return 0;
}

      