
fun main(args:Array<String>):Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        Array(n){
            val arg = readLine()!!.trim().split(' ').map(String::toInt)
            val bowringScore = BowringScore()
            arg.drop(1).forEach { bowringScore.throwBall(it) }
            Pair(arg.first(), bowringScore.currentScore)
        }.sortedByDescending { it.second * 100000 - it.first }.forEach {
            println("${it.first} ${it.second}")
        }

    }
}
class BowringScore{
    private var mIsNextSpare = 0
    private var mIsNextStrike = 0
    var currentScore:Int = 0
        private set
    private var mFirst = true
    private var flame = 0
    private var mRest:Int = 10
    fun throwBall(num:Int):Unit {
        if (mFirst) ++flame
        if (flame <= 10) {
            currentScore += num * (1 + mIsNextSpare + mIsNextStrike)
            mIsNextSpare = mIsNextStrike
            mIsNextStrike = 0
            if (mFirst) {
                if (num == 10) {
                    mIsNextStrike = 1
                } else {
                    mRest -= num
                    mFirst = false
                }
            } else {
                if (num == mRest) {
                    mIsNextSpare += 1
                }
                mRest = 10
                mFirst = true
            }
        }else{
            currentScore += num * (mIsNextSpare + mIsNextStrike)
            mIsNextSpare = mIsNextStrike
            mIsNextStrike = 0
        }
    }
}
