#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    vector<P> a;
    a.resize(n+1);
    string s;
    getline(cin,s);
    for(int j=0; j<n; j++) {
      getline(cin,s);
      stringstream ss;
      ss << s;
      ss >> a[j].second;
      a[j].second*=-1;
      a[j].first=0;
      vector<int> b;
      int x;
      while(ss >> x) b.push_back(x);
      int i=0,k=0;
      vector<int> c;
      c.resize(b.size()+1);
      fill(c.begin(),c.end(),0);
      while(i<b.size()) {
        k++;
        a[j].first+=b[i];
        if(i&&c[i-1]) a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i]==10) {
          if(k<10)c[i]=2;
          i++;
          continue;
        }
        i++;
        if(i>=b.size()) break;
        a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i-1]+b[i]==10) {
          if(k<10)c[i]=1;
          i++;
          continue;
        }
        i++;
        if(i>=b.size()) break;
        if(k==10) {
          a[j].first+=b[i];
          i++;
        }
      }
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<n; i++) cout << a[i].second << " " << -a[i].first << endl;
  }
  return 0;
}