#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <sstream>
using namespace std;

int main(){
  int m;
  while(cin >> m, m){
    vector<string> I(m);
    vector<int> S(m,0);
    for(int i = 0; i < m; ++i){
      cin >> I[i];
      vector<int> t;
      for(int j = 0; j < 20; ++j){
        int s;
        cin >> s;
        if(j < 18 and s == 10) ++j;
        t.push_back(s);
      }
      if(t[t.size()-1]+t[t.size()-2] >= 10){
        int s;
        cin >> s;
        t.push_back(s);
      }
      int l = 0;
      for(size_t j = 0; j < t.size(); ++j){
        int tmp = t[j], k = 0;
        ++l;
        if(tmp < 10 and j+1 < t.size()) tmp += t[++j], ++k;
        if(l < 10 and tmp == 10){
          if(j+1 < t.size()) S[i] += t[j+1];
          if(k == 0 and j+2 < t.size()) S[i] += t[j+2];
        }
        S[i] += tmp;
      }
      
    }
    vector<pair<int,string>> V;
    for(int i = 0; i < m; ++i)
      V.emplace_back(S[i],I[i]);
    sort(V.rbegin(), V.rend());
    for(auto p : V)
      cout << p.second << " " << p.first<< endl;
  }
}

