#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > score(n);
        for(int i=0; i<n; ++i){
            cin >> score[i].second;
            score[i].second = -score[i].second;

            vector<vector<int> > pin(10, vector<int>(2, 0));
            for(int j=0; j<10; ++j){
                cin >> pin[j][0];
                if(j == 9 || pin[j][0] != 10)
                    cin >> pin[j][1];
                score[i].first += pin[j][0] + pin[j][1];

                if(j > 0 && pin[j-1][0] == 10){
                    score[i].first += pin[j][0] + pin[j][1];
                    if(j > 1 && pin[j-2][0] == 10)
                        score[i].first += pin[j][0];
                }
                else if(j > 0 && pin[j-1][0] + pin[j-1][1] == 10)
                    score[i].first += pin[j][0];
            }
            if(pin[9][0] + pin[9][1] == 10 || pin[9][0] + pin[9][1] == 20){
                int a;
                cin >> a;
                score[i].first += a;
            }
        }

        sort(score.rbegin(), score.rend());
        for(int i=0; i<n; ++i)
            cout << -score[i].second << ' ' << score[i].first << endl;
    }
}