using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication11 {
    class Program {

        

        static void Main(string[] args) {
            new Program().solve();
        }

        void solve() {
            while (true) {
                int num_Player = int.Parse(Console.ReadLine());
                if (num_Player == 0) {
                    return;
                }
                List<ResultBowling> allResult = new List<ResultBowling>();
                for (int i = 0; i < num_Player; i++) {
                    ResultBowling result = new ResultBowling();
                    string input = Console.ReadLine();
                    string[] scoreCard = input.Split(' ');
                    result.calcScore(scoreCard);
                    allResult.Add(result);
                }
                
                allResult.Sort(delegate(ResultBowling a, ResultBowling b) {
                    if (b.totalScore != a.totalScore) return b.totalScore - a.totalScore;
                    else return a.playerNumber - b.playerNumber;
                });

                for (int i = 0; i < allResult.Count; i++) {
                    Console.WriteLine(allResult[i].playerNumber.ToString()+" "+allResult[i].totalScore.ToString());
                }
            }
        }

    }

    class ResultBowling {
        int[] scoreCard;
        public int playerNumber;
        public int totalScore;

        public void calcScore(string[] input) {
            playerNumber = int.Parse(input[0]);
            scoreCard = new int[input.Length - 1];
            for (int i = 0; i < scoreCard.Length; i++) {
                scoreCard[i] = int.Parse(input[i+1]);
            }

            Flame[] result = new Flame[10];
            for (int i = 0; i < result.Length; i++) {
                result[i] = new Flame();
            }

            bool inFrame = false;
            int flameCount = 0;
            int s = 0;
            while (true) {
                if (flameCount == 9) {
                    if (scoreCard.Length - s == 3) {
                        result[flameCount].setScore(scoreCard[s], scoreCard[s + 1], scoreCard[s + 2]);
                        break;
                    } else {
                        result[flameCount].setScore(scoreCard[s], scoreCard[s + 1], 0);
                        break;
                    }
                }
                if (scoreCard[s] == 10) {
                    if (inFrame) {
                        result[flameCount].setScore(0, scoreCard[s], 0);
                        flameCount++;
                        s++;
                        inFrame = false;
                    } else {
                        result[flameCount].setScore(scoreCard[s], 0, 0);
                        flameCount++;
                        s++;
                    }  
                } else {
                    if (!inFrame) { 
                        s++;
                        inFrame = true;
                    } else {
                        result[flameCount].setScore(scoreCard[s - 1], scoreCard[s], 0);
                        flameCount++;
                        s++;
                        inFrame = false;
                    }
                }
            }
            
            for (int f = 0; f < result.Length; f++){
                if (f == 9) {
                    totalScore += result[f].getScore()[0] + result[f].getScore()[1] + result[f].getScore()[2];
                } else if (f == 8) {
                    if (result[f].getIsStrike()){
                        totalScore += 10 + result[f + 1].getScore()[0] + result[f + 1].getScore()[1];
                    } else if (result[f].getIsSpare()){
                        totalScore += 10 + result[f + 1].getScore()[0];
                    } else {
                        totalScore += result[f].getScore()[0] + result[f].getScore()[1];
                    }
                } else if (f < 8) {
                    if (result[f].getIsStrike()) {
                        if (result[f+1].getIsStrike()){
                            totalScore += 20 + result[f+2].getScore()[0];
                        } else {
                            totalScore += 10 + result[f + 1].getScore()[0] + result[f + 1].getScore()[1];
                        }
                    } else if(result[f].getIsSpare()) {
                        totalScore += 10 + result[f + 1].getScore()[0];
                    } else {
                        totalScore += result[f].getScore()[0] + result[f].getScore()[1];
                    }
                } 
            }
        }

        class Flame {
            int first, second,third;
            bool isStrike, isSpare;
            public void setScore(int a,int b,int c) {
                first = a;
                second = b;
                third = c;
                if (a == 10) {
                    isStrike = true;
                    return;
                }
                if (a < 10 && a + b == 10) {
                    isSpare = true;
                    return;
                }
            }

            public int[] getScore() {
                return new int[] { first, second, third };
            }

            public bool getIsStrike() {
                return isStrike;
            }
            public bool getIsSpare() {
                return isSpare;
            }
        }
    }
    
}

Measured memory_bytes: 9244