#include<bits/stdc++.h>
using namespace std;

class T{

public:
  int indx;
  int point;

  bool operator < (const T &a)const{
    if(point == a.point){
      return indx < a.indx;
    }else{
      return point > a.point;
    }
  }
};

int main(){


  vector<T> result;
  int game[21];
  int m;


  while(cin >> m && m){
    result = vector<T>(m);
    for(int i=0; i<m; i++){
      result[i].point=0;
    }

    for(int i=0; i<m; i++){

      cin>>result[i].indx;

      int indx=0;
      while(indx < 20){

	cin >> game[indx];

	//10game
	if(indx==18){
	  cin >> game[++indx];

	  if(game[indx-1]+game[indx] >= 10){
	    cin >> game[++indx];
	  }
	  else{
	    game[++indx]=0;
	  }
	  break;
	}
	//1 to 9 game
	else{
	  if(game[indx]==10){
	    game[++indx]=-1;
	    indx++;
	  }
	  else{
	    cin >> game[++indx];
	    indx++;
	  }
	}
      }
      //while

      /*  cout << endl;
      for(int m=0; m<21; m++){
	cout << game[m] << ' ';
      }cout << endl;
      */

      //score
      indx = 0;
      while(indx<21){

	if(indx == 18){
	  result[i].point+= game[18]+game[19]+game[20];
	  break;
	}
	else{

	  result[i].point+=game[indx];

	  if(game[indx]==10){
	    int work=0;
	    int k=2;
	    while(work<2){
	      if(game[indx+k]!=-1){
		result[i].point+=game[indx+k];
		work++;
	      }
	      k++;
	    }
	    indx+=2;
	  }
	  else{
	    result[i].point+=game[++indx];
	    if(game[indx-1]+game[indx]==10)
	      result[i].point+=game[indx+1];

	    indx++;
	  }
	}

	//cout << "test " <<result[i][1] << endl;;

      }	
      
    }

    //sort
    sort(result.begin(), result.end());
 
    for(int i=0; i<m; i++){
      cout << result[i].indx << ' ' << result[i].point << endl;
    }

  }


  return 0;
}