#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct P{
  int n, p;
  P(int n, int p):n(n),p(p){};
  bool operator<(const P& r)const{
    return p == r.p ? n > r.n : p < r.p;
  }
};

int m;

int solve(int *f, int n){
  int res = 0;
  //  printf("%d ", *f);
  if(*f == 1 || *f == 2){ res = n*2; (*f)--;}
  else if(*f == 3){ res = n*3; *f = 1;}
  else res = n;
  //  printf("%d\n", *f);
  return res;
}

int main(){
  while(scanf("%d", & m) && m){
    int a, b, sf, sum, n;
    priority_queue<P>q;
    rep(i, m){
      sf = sum = 0;
      scanf("%d", &n);
      rep(j, 9){
	//	printf("j: %d\n", j);
	//	printf("%d\n", sf);
	//	printf("%d\n", sum);
	scanf("%d", &a);
	sum += solve(&sf, a);
	if(a == 10){ sf += 2; continue;}


	scanf("%d", &b);
	sum += solve(&sf, b);
	if(a + b == 10){ sf += 1; continue;}

      }
      scanf("%d", &a);
      //      printf("sf:%d\n", sf);
      if(a == 10){
	sum += solve(&sf, a);
	sf += 2;
	//	printf("%d %d\n", sum, sf);
	scanf("%d", &a);
	sum += solve(&sf, a) - a;
	//	printf("%d %d\n", sum, sf);
	scanf("%d", &a);
	sum += a;
      }else{
	sum += solve(&sf, a);
	scanf("%d", &b);
	sum += solve(&sf, b);
	if(a + b == 10){
	  scanf("%d", &b);
	  sum += b;
	}
      }
      q.push(P(n, sum));
    }
    while(!q.empty()){
      P p = q.top(); q.pop();
      printf("%d %d\n", p.n, p.p);
    }
  }
  return 0;
}