#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,a,b,k=0;
      cin>>name;
      for(int i=0;i<10;i++){
	cin>>a;score+=a;
	if(k&4) score+=a,k&=3;
	if(k&2) score+=a;
	if(k&1) score+=a,k&=6;
	if(a==10){
	  if(k&2)k|=4;
	  k|=2;
	}
	else{cin>>b;score+=b;
	  if(k&2)score+=b,k&=5;
	  if(a+b==10)k|=1;}
      }
      if(k&2){cin>>a>>b;score+=k&4?2*a+b:a+b;}
      if(k&1){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;
  }
}