#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

struct Frame {
    int one, two, third, score;
    bool strike, spare;
    Frame() { score = 0; strike = spare = false; one = two = third = 0; }
};

struct Player {
    int id, score;
    Player() {}
};

bool operator < (const Player &a, const Player &b)
{
    return (a.score == b.score) ? (a.id < b.id) : (a.score > b.score);
}

int Caluculate(string s)
{
    int data[22];
    int n = 0, index = 1;

    // parse number
    while (index < s.size()) {
        int num = 0;
        while (true) {
            if ('0' <= s[index] && s[index] <= '9') {
                num *= 10;
                num += (int)(s[index++] - '0');
            }
            else
                break;
        }
        index++;
        data[n++] = num;
    }

    // スコア
    Frame frame[10];
    double game = 1.0;
    for (int i = 0; i < n; ++i) {
        if (game >= 10.0) { // 10ゲーム目
            frame[9].score += data[i];
            if (game == 10.0)
                frame[9].one = data[i];
            else if (game == 10.5)
                frame[9].two = data[i];
            else if (game == 11.0)
                frame[9].third = data[i];
            game += 0.5;
        }
        else if (game - (int)game != 0.0) {  // 後半
            if (frame[(int)game - 1].one + data[i] == 10) // スペア
                frame[(int)game - 1].spare = true;
            frame[(int)game - 1].two = data[i];
            game += 0.5;
        }
        else { // 前半
            if (data[i] == 10) { // ストライク
                frame[(int)game - 1].one = 10;
                frame[(int)game - 1].strike = true;
                game += 1.0;
            }
            else {
                frame[(int)game - 1].one = data[i];
                game += 0.5;
            }
        }
    }

    // 各フレーム(1-9)でのスコア計算
    for (int i = 0; i < 9; ++i) {
        if (frame[i].spare) // スペア
            frame[i].score = 10 + frame[i + 1].one;
        else if (frame[i].strike) { // ストライク
            frame[i].score = 10;
            if (i == 8) // 第9ホール
                frame[i].score += frame[i + 1].one + frame[i + 1].two;
            else if (frame[i + 1].strike)
                frame[i].score += 10 + frame[i + 2].one;
            else
                frame[i].score += frame[i + 1].one + frame[i + 1].two;
        }
        else
            frame[i].score = frame[i].one + frame[i].two;
    }

    // ゲームのスコア計算
    int res = 0;
    for (int i = 0; i < 10; ++i)
        res += frame[i].score;

    return res;
}

int main()
{
    int m;

    while (cin >> m, m) {
        vector<Player> player(m);

        // Input
        for (int i = 0; i < m; ++i) {
            string data;
            cin >> player[i].id;
            getline(cin, data);

            player[i].score = Caluculate(data);
        }

        sort(player.begin(), player.end());

        // Output
        for (int i = 0; i < m; ++i)
            cout << player[i].id << " " << player[i].score << endl;
    }

    return 0;
}