#include <iostream>
#include <vector>
#include <sstream>
#include <map>
#include <set>
using namespace std;
int point(vector<int>& v)
{
  int id = 0,pt = 0;
  for(int i=0; i<9; i++){
    if(v[id] == 10){
      pt += 10 + v[id+1] + v[id+2];
      id++;
    }else if(v[id] + v[id+1] == 10){
      pt += 10 + v[id+2];
      id += 2;
    }else{
      pt += v[id] + v[id+1];
      id += 2;
    }
  }
  while(id < v.size()){
    pt += v[id++];
  }
  return pt;
}
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    map<int,set<int> > ma;
    for(int i=0; i<n; i++){
      int num;
      cin >> num;
      string s;
      getline(cin,s);
      stringstream str(s);
      vector<int> v;
      while(!str.eof()){
        int j;
        str >> j;
        v.push_back(j);
        str.ignore();
      }
      ma[point(v)].insert(num);
    }
    for(map<int,set<int> >::reverse_iterator r=ma.rbegin(); r!=ma.rend(); r++){
      int pt = (*r).first;
      set<int> s = (*r).second;
      for(set<int>::iterator it=s.begin(); it!=s.end(); it++){
        cout << *it << " " << pt << endl;
      }
    }
  }
  return 0;
}