#include <iostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <set>

using namespace std;

template<class T1, class T2>
T1 lexical_cast(T2 a){
  T1 tmp;
  stringstream ss;
  ss << a; ss >> tmp;
  return tmp;
}

int main(){
  string buff;
  int n;

  while(getline(cin, buff), n = lexical_cast<int>(buff)){
    set<pair<int, int>, greater<pair<int, int> > > ans;

    for(int i = 0; i < n; i++){
      stringstream ss;
      int id;
      int point = 0;
      int frame = 0;

      getline(cin, buff); ss << buff; ss >> id;
      
      vector<int> v((istream_iterator<int>(ss)),
		    istream_iterator<int>());

      enum state{
	NONE = 0,
	SPARE = 1,
	STRIKE = 2
      };

      state prev  = NONE;
      state pprev = NONE;
      
      int vv = 0;
      for(int f = 0; f < 10; f++){
	int now = v[vv++];

	point += now;
	if(prev  != NONE)   point += now;
	if(pprev == STRIKE) point += now;

	if(now == 10){
	  if(f == 9){
	    int now2 = v[vv++];
	    point += now2;
	    if(prev == STRIKE) point += now2;
	    if(now2 == 10)
	      point += v[vv++];
	  }

	  pprev = prev;
	  prev  = STRIKE;
	}else{
	  int now2 = v[vv++];
	  point += now2;

	  if(prev  == STRIKE) point += now2;

	  pprev = NONE;
	  prev  = NONE;

	  if(now + now2 == 10){
	    if(f == 9){
	      int now3 = v[vv++];
	      point += now3;
	    }
	    prev = SPARE;
	  }
	}
	// cout << "f=" << f+1 << ": " << point << " ";
	// cout << "prev=" << prev << " " << "pprev=" << pprev << endl;
      }

      ans.insert(make_pair(point, id));
    }

    for(set<pair<int, int> >::iterator it = ans.begin();
	it != ans.end();
	++it){
      cout << it->second << " " << it->first << endl;
    }
  }

  return 0;
}