#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  for(int d;cin>>d,d;){
    vector<pair<int,int> > result;
    for(int i=0;i<d;i++){
      int name,score=0;
      cin>>name;
      int a,b;
      bool spare=false,strike=false,dbl=false;
      for(int i=0;i<10;i++){
	cin>>a;
	score+=a;
	if(dbl) score+=a,dbl=false;
	if(strike) score+=a;
	if(spare) score+=a,spare=false;
	if(a==10){
	  if(strike)dbl = true;
	  strike = true;
	}
	else{
	  cin>>b;
	  score+=b;
	  if(strike)score+=b,strike=false;
	  if(a+b==10)spare = true;
	}
      }
      if(strike){
	cin>>a>>b;
	if(dbl)score+=a;
	score+=a+b;
      }
      if(spare){
	cin>>a;
	score+=a;
      }
      result.push_back(mp(-score,name));
    }
    sort(result.begin(),result.end());
    for(int i=0;i<d;i++){
      cout<<result[i].second<<" "<<-result[i].first<<endl;
    }
  }
  return 0;
}