#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    while(1){
        int m; cin>>m;
        if(m == 0) return 0;

        vector<int> id(m);
        vector<vector<int>> score(m);
        for(int i=0; i<m; i++){
            cin>>id[i];
            
            int turn = 1;
            int cnt = 0;
            int sum = 0;
            while(1){
                int s; cin>>s;
                score[i].eb(s);
                sum += s;
                cnt++;

                if(turn == 10){
                    if(sum == 10){
                        int s1, s2; cin>>s1>>s2;
                        score[i].eb(s1);
                        score[i].eb(s2);
                    }
                    else{
                        int s1; cin>>s1;
                        if(s + s1 == 10){
                            int s2; cin>>s2;
                            score[i].eb(s1);
                            score[i].eb(s2);
                        }
                        else{
                            score[i].eb(s1);
                        }
                    }

                    break;
                }

                if(sum == 10 && cnt == 1){
                    cnt = 0;
                    turn++;
                    sum = 0;
                }
                else if(sum == 10 && cnt == 2){
                    cnt = 0;
                    turn++;
                    sum = 0;
                }
                else if(cnt == 2){
                    cnt = 0;
                    turn++;
                    sum = 0;
                }
            }
        }

        vector<P> fans(m);
        for(int i=0; i<m; i++){
            int ID = id[i];
            int turn = 1;
            int cnt = 0;
            int sum = 0;
            int ans = 0;
            for(int j=0; j<score[i].size(); j++){
                sum += score[i][j];
                ans += score[i][j];
                cnt++;

                if(turn == 10) continue;

                if(sum == 10 && cnt == 1){
                    ans += score[i][j+1];
                    ans += score[i][j+2];
                    turn++;
                    cnt = 0;
                    sum = 0;
                }
                else if(sum == 10 && cnt == 2){
                    ans += score[i][j+1];
                    turn++;
                    cnt = 0;
                    sum = 0;
                }
                else if(cnt == 2){
                    turn++;
                    cnt = 0;
                    sum = 0;
                }
            }

            fans[i] = P(ans, -ID);
        }

        sort(fans.begin(), fans.end(), greater<P>());

        for(int i=0; i<m; i++){
            cout << -fans[i].second << " " << fans[i].first << endl;
        }
    }
}


Measured memory_bytes: 3148