#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
namespace std {
  bool operator < (const P& a, const P& b) { return a.second != b.second ? a.second > b.second : a.first < b.first; }
}

vector<int> split(string &str, char delim){
  stringstream ss(str);
  string tmp;
  vector<int> res;
  while(getline(ss, tmp, delim)) res.push_back(atoi(tmp.c_str()));
  return res;
}

int solve(vector<int> v){
  int t = 1, i = 1, res = 0;
  while(i < v.size()){
    if(t >= 10){
      res += v[i++];
    } else if(v[i] >= 10){
      res += v[i] + v[i + 1] + v[i + 2];
      ++i;
      ++t;
    } else if(v[i] + v[i + 1] >= 10){
      res += v[i] + v[i + 1] + v[i + 2];
      i += 2;
      ++t;
    } else{
      res += v[i] + v[i + 1];
      i += 2;
      ++t;
    }
  }
  return res;
}

int main() {
  int N;
  while(cin >>N && N){
    vector<P> ps(N);
    string s; getline(cin, s);
    REP(i, N){
      getline(cin, s);
      vector<int> v = split(s, ' ');
      ps[i] = P(v[0], solve(v));
    }
    SORT(ps);
    REP(i, ps.size()) cout <<ps[i].first <<" " <<ps[i].second <<endl;
  }
  return 0;
}