#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <fstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

bool comp(PI a,PI b){
  if(a.F==b.F)return a.S<b.S;
  return a.F>b.F;
}


main(){
  int m;
  while(cin>>m,m){
    vector<PI> po;

    rep(i,m){
      int num,p=0;
      cin>>num;
      int t2=0,t1=0;
      int flame=0,fi;
      int last=0;
      int sl1[10],sl2[10];
      memset(sl1,0,sizeof(sl1));
      memset(sl2,0,sizeof(sl2));

      while(true){
	int t;
	if(flame==9){
	  cin>>t;
	  int su=t;
	  sl1[flame]=t;
	  cin>>t;
	  su+=t;
	  sl2[flame]=t;
	  if(su>=10){
	    cin>>last;
	  }
	  break;
	}else{
	  cin>>t;
	  if(t==10){
	    sl1[flame]=10;
	    ++flame;
	    continue;
	  }
	  sl1[flame]=t;
	  cin>>t;
	  sl2[flame]=t;
	}
	++flame;
      }

      int sum=0;
      rep(j,10){
	if(j!=9){
	  sum+=sl1[j];
	  if(sl1[j]==10){
	    sum+=sl1[j+1];
	    if(sl1[j+1]==10){
	      if(j+2<10)sum+=sl1[j+2];
	      else sum+=sl2[j+1];
	    }else sum+=sl2[j+1];
	  }else{
	    sum+=sl2[j];
	    if(sl1[j]+sl2[j]==10){
	      sum+=sl1[j+1];
	    }
	  }
	}else{
	  sum+=sl1[j]+sl2[j]+last;
	}
      }
      po.pb(mp(sum,num));
    }
    sort(ALL(po),comp);
    rep(i,po.size()){
      cout<<po[i].S<<" "<<po[i].F<<endl;
    }
  }
}