#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <sstream>
#include <cstdio>
using namespace std;
typedef pair <int,int> p;
vector<p> V;

p score(string str) {
  stringstream ss;
  string s;
  int number;
  ss << str;
  ss >> number;
  int frame = 1,play=1,point[11] = {};
  int spare[22] = {},strike[22] = {};
  bool check = true;
  while(ss >> s) {
    int pin = atoi(s.c_str());
    if(check) point[frame] += pin;
    for(int i=1;i<11;i++) {
      if(strike[i]>0) {
	point[i]+=pin;
	strike[i]--;
      }
      if(spare[i]>0) {
	point[i]+=pin;
	spare[i]--;
      }
    }
    if(play==1&&pin==10) {
      strike[frame]=2;
      if(frame!=10) frame++;
      else check = false;
      play=1;
      continue;
    }
    if(play==1&&pin!=10) {
      play++;
      continue;
    }
    if(play==2&&point[frame]==10) {
      spare[frame] = 1;
      if(frame!=10)frame++;
      else check = false;
      play=1;
      continue;      
    }
    if(play==2&&point[frame]!=10) {
      frame++;
      play=1;
      continue;
    }
  }
  int sum=0;
  for(int i=1;i<=10;i++) {
    //  cout << point[i] << " ";
    sum += point[i];
  }
  // cout << sum << endl;
  p ans;
  ans.first = sum;
  ans.second = number;
    return ans;
}
  
int main() {
  int m;
  string str;
  while(scanf("%d\n",&m),m) {
    for(int i=0;i<m;i++) {
      p temp;
      getline(cin,str);
      temp = score(str);
      V.push_back(temp);
    }
    sort(V.rbegin(),V.rend());
    for(unsigned int i=0;i<V.size();i++) {
      cout << V[i].second << " " << V[i].first << endl;
    }
    V.clear();
  }
}