#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


II solve( int no, VI A ) {
    VI F(10, 0), S(10, 0), C(10, 0);
    VI T(10, 0);
    int t = 0;
    for ( int i = 0; i < 10; ++ i ) {
        F[i] = 0, S[i] = 0, C[i] = 0;
        if ( i == 9 ) {
            F[i] = A[t++];
            S[i] = A[t++];
            C[i] = 0;
            if ( F[i] + S[i] >= 10 ) C[i] = A[t++];
        } else {
            if ( A[t] == 10 ) {
                F[i] = A[t++];
            } else {
                F[i] = A[t++];
                S[i] = A[t++];
            }
        }
    }

    for ( int i = 0; i < 10; ++ i ) {
        T[i] = F[i] + S[i] + C[i];
    }

    int addScore = 0;
    for ( int i = 0; i < 9; ++ i ) {
        if ( F[i] == 10 ) {
            if ( i < 8 ) {
                if ( F[i+1] == 10 ) {
                    addScore += 10 + F[i+2];
                } else {
                    addScore += F[i+1] + S[i+1];
                }
            } else if ( i == 8 ) {
                addScore += F[9] + S[9];
            }
        } else if ( F[i] + S[i] >= 10 ) {
            addScore += F[i+1];
        }
    }
    return II( accumulate( T.begin(), T.end(), 0 ) + addScore, no );
}

int main() {
    string line;
    while ( getline( cin, line ) ) {
        if ( line == "0" ) break;
        ISS iss( line );
        int n;
        iss >> n;
        VII scores( n );
        for ( int i = 0; i < n; ++ i ) {
            getline( cin, line );
            ISS iss( line );
            int no;
            iss >> no;
            int a;
            VI A;
            while ( iss >> a ) A.push_back( a );
            scores[i] = solve( no, A );
        }
        sort( scores.rbegin(), scores.rend() );
        for ( int i = 0; i < n; ++ i ) {
            cout << scores[i].second << " " << scores[i].first << endl; 
        }
    }
    return 0;
}