#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <sstream>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int M;
std::vector<P> results;

int main(){
    while(std::cin >> M, M != 0){
        results.clear();

        REP(i, M){
            int id;
            std::cin >> id;

            scanf("%*c");

            int pins[30], length = 0;
            {
                std::string s;
                std::getline(std::cin, s);
            
                std::stringstream ss(s);
                while(std::getline(ss, s, ' ')){
                    pins[length] = std::stoi(s);
                    length += 1;
                }
            }

            int points = 0;
            {
                int frame = 0, index = 0;
                while(frame < 10){
                    if(frame == 9){
                        if(index+3 == length){
                            points += pins[index] + pins[index+1] + pins[index+2];
                        }else{
                            points += pins[index] + pins[index+1];
                        }
                    }else{
                        if(pins[index] == 10){
                            points += 10;
                            if(index+2 < length){points += pins[index+1] + pins[index+2]; index += 1;}
                            else if(index+1 < length){points += pins[index+1]; index += 1;}
                        }else if(index+1 < length && pins[index] + pins[index+1] == 10){
                            points += 10;
                            if(index+2 < length){points += pins[index+2]; index += 2;}
                        }else{
                            points += pins[index] + pins[index+1];
                            index += 2;
                        }
                    }

                    frame += 1;
                }
            }

            results.push_back(mp(points, id));
        }

        std::sort(results.begin(), results.end(),
                  [](const P& lhs, const P& rhs){if(lhs.first != rhs.first){return lhs.first > rhs.first;} return lhs.second < rhs.second;});


        REP(i, M){
            printf("%d %d\n", results[i].second, results[i].first);
        }
    }
}