#include<iostream>
#include<vector>

using namespace std;

vector<int> Name;
typedef struct{int number; int point;} SCORE;

vector <int> toV(string in){
  vector<int> out;
  for(int i = 0; i < in.length(); i++){
    int num = 0;
    while(in[i] != ' '){
      num *= 10;
      num += in[i]-'0';
      i++;
    }
    out.push_back(num);
  }
  return out;
}

int score(vector<int> V){
  int j= 0;
  int sum = 0;
  int po;
  for(int i = 1; i < V.size(); i++){
    j++;
    if(j == 10){
      po = i;
      break;
    }
    if(V[i] == 10) sum += 10+V[i+1]+V[i+2];
    else if(V[i] + V[i+1] == 10){
      i++;
      sum += 10+V[i+1];
    }else{
      sum += V[i] + V[i+1];
      i++;
    }
  }
  if(V[po] + V[po+1] >= 10) sum += V[po] + V[po+1] + V[po+2];
  else sum += V[po]+V[po+1];
  return sum;
}

int main(){

  int in;
  while(cin >> in && in){
    SCORE SC[in];
    Name.clear();
    string t;
    getline(cin,t);
    vector<int> V;
    for(int i = 0; i < in; i++){
      string s;
      getline(cin,s);
      s += ' ';
      V = toV(s);
      Name.push_back(V[0]);
      SC[i].number = V[0];
      SC[i].point = score(V);
    }
    for(int i = 0; i < in; i++){
      for(int j = 0; j < in-i-1; j++){
	if(SC[j].point < SC[j+1].point) swap(SC[j],SC[j+1]);
	else if(SC[j].point == SC[j+1].point &&
		SC[j].number > SC[j+1].number) swap(SC[j],SC[j+1]);
      }
    }

    for(int i = 0; i < in; i++) cout << SC[i].number  << " " << SC[i].point<< endl;
  }
  return 0;
}