#include <iostream>
#include <algorithm>
#define N 40
using namespace std;

int d[N];
int p[N];
void mergeSort(int, int);
void merge(int, int, int);
int main(){
  int n;
  int ans1[N], ans2[N];
  int data[21];
  while(1){
    cin >> n;
    if(n==0) break;

    for(int i=0;i<n;i++){
      cin >> d[i];
      int size;
      char tmp;
      for(int j=0;;j++){
        scanf("%c", &tmp);
        if(tmp=='\n'){
          size=j;
          break;
        }
        scanf("%d", &data[j]);
      }
      int now=1;
      p[i]=0;
      int f=1;
      for(int count=0;count<size;count++){
        if(f==10){
          if(data[count]==10 & data[count+1]==10 && data[count+2]==10){
            p[i]+=30;
          }
          else if(data[count]==10){
            p[i]+=10+data[count+1]+data[count+2];
          }
          else if((data[count]+data[count+1]==10)){
            p[i]+=10+data[count+2];
          }
          else p[i]+=data[count]+data[count+1];
          break;
        }
        if(now==1){
          if(data[count]==10){
            p[i]+=10+data[count+1]+data[count+2];
            f++;
            continue;
          }
          else{
            p[i]+=data[count];
            now=2;
          }
        }
        else{
          p[i]+=data[count];
          if((data[count]+data[count-1])==10){
            p[i]+=data[count+1];
          }
          now=1;
          f++;
        }
      }
    }
    mergeSort(0, n);
    for(int i=0;i<n;i++){
      ans1[i]=p[n-i-1];
      ans2[i]=d[n-i-1];
    }
    for(int i=0;i<n-1;i++){
      int left, right;
      if(ans1[i]==ans1[i+1]){
        left=i;
        for(int j=i+1;;j++){
          if(j>=n){
            right=n;
            i=j-1;
            break;
          }
          if(ans1[i]!=ans1[j]){
            right=j;
            i=j-1;
            break;
          }
        }
        sort(ans2+left, ans2+right);
      }
    }
    for(int i=0;i<n;i++){
      cout << ans2[i] << ' ' << ans1[i] << endl;
    }
  }
  return 0;
}

void merge(int left, int mid, int right){
  int L[N/2+2], R[N/2+2];
  int l[N/2+2], r[N/2+2];
  int n1=mid-left;
  int n2=right-mid;
  for(int i=0;i<n1;i++){
    L[i]=p[left+i];
    l[i]=d[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=p[mid+i];
    r[i]=d[mid+i];
  }
  L[n1]=R[n2]=2147483647;
  l[n1]=r[n2]=2147483647;
  int i, j;
  i=j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j]){
      p[k]=L[i];
     d[k]=l[i++];
    }
    else{
      p[k]=R[j];
      d[k]=r[j++];
    }
  }
}

void mergeSort(int left, int right){
  if(left>=right-1) return;
  int mid=(left+right)/2;
  mergeSort(left, mid);
  mergeSort(mid, right);
  merge(left, mid, right);
}