Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

type entry struct {
	id, score int
}

type lessFunc func(p1, p2 *entry) bool

type multiSorter struct {
	entries []entry
	less    []lessFunc
}

func (ms *multiSorter) sort(entries []entry) {
	ms.entries = entries
	sort.Sort(ms)
}

func OrderedBy(less ...lessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}

func (ms *multiSorter) Len() int {
	return len(ms.entries)
}

func (ms *multiSorter) Swap(i, j int) {
	ms.entries[i], ms.entries[j] = ms.entries[j], ms.entries[i]
}

func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.entries[i], &ms.entries[j]
	var k int
	for k = 0; k < len(ms.less)-1; k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	for scanner.Scan() {
		m, _ := strconv.Atoi(scanner.Text())
		if m == 0 {
			break
		}
		results := make([]entry, 0)
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			data := make([]int, len(buf))
			for i := range data {
				data[i], _ = strconv.Atoi(buf[i])
			}
			id, score := score(data)
			results = append(results, entry{id, score})
		}
		score_axis := func(e1, e2 *entry) bool {
			return e1.score > e2.score
		}
		id_axis := func(e1, e2 *entry) bool {
			return e1.id < e2.id
		}
		OrderedBy(score_axis, id_axis).sort(results)
		// log.Println(results)
		for _, e := range results {
			fmt.Printf("%d %d\n", e.id, e.score)
		}
	}
}

func score(input []int) (int, int) {
	id := input[0]
	data := input[1:]
	frame := 1
	scores := make([]int, 11)
	for frame <= 10 {
		if data[0] == 10 {
			scores[frame] = data[0] + data[1] + data[2]
			data = data[1:]
			frame += 1
		} else if data[0]+data[1] == 10 {
			scores[frame] = data[0] + data[1] + data[2]
			data = data[2:]
			frame += 1
		} else {
			scores[frame] = data[0] + data[1]
			data = data[2:]
			frame += 1
		}
	}
	sum := 0
	for i, v := range scores {
		if i != 0 {
			sum += v
		}
	}
	return id, sum
}

Python: def f1():
    frame = 1
    total = 0
    i = 0
    while frame < 10:
        if score[i] == 10:
            total += (score[i] + score[i+1] + score[i+2])
            i += 1
        elif score[i] + score[i+1] == 10:
            total += (score[i] + score[i+1] + score[i+2])
            i += 2
        else:
            total += (score[i] + score[i+1])
            i += 2
        frame += 1
    else:
        total += sum(score[i:])
        res[sn] = total

def f2():
    for k, v in sorted(res.items(), key=lambda x:(x[1], x[0]), reverse=True):
        print -k, v

while True:
    n = input()
    if n == 0: break
    res = {}
    for i in range(n):
        L = map(int, raw_input().split())
        sn = -L[0]
        score = L[1:]
        f1()
    else:
        f2()

Python: # AOJ 0152 Bowling
# Python3 2018.6.21 bal4u

while True:
	n = int(input())
	if n == 0: break
	tbl = {}
	for _ in range(n):
		p = list(map(int, input().split()))
		id, s = p.pop(0), 0
		for f in range(9):
			if p[0] == 10: s += p[0]+p[1]+p[2]
			else:
				s += p[0]+p[1]
				if p[0]+p[1] == 10: s += p[2]
				p.pop(0)
			p.pop(0)
		s += p[0]+p[1]  #10番フレーム
		if p[0] == 10 or p[0]+p[1] == 10: s += p[2]
		tbl[id] = s
	for i in sorted(tbl.items(), key=lambda x:(-x[1],x[0])): print(*i)

Python: while 1:
    M = int(input())
    if M == 0:
        break
    S = []
    for i in range(M):
        t, *score = map(int, input().split())
        frame = rd = cum = 0
        L = len(score)
        res = sum(score)
        for i in range(L):
            s = score[i]
            if rd == 0:
                cum = s
                if s == 10:
                    res += score[i+1] + score[i+2]
                    frame += 1
                else:
                    rd = 1
            else:
                cum += s
                if cum == 10:
                    res += score[i+1]
                frame += 1
                rd = 0
            if frame == 9:
                break
        S.append((-res, t))
    S.sort()
    for x, y in S:
        print(y, -x)

Python: # AOJ 0152 Bowling
# Python3 2018.6.20 bal4u

while True:
	n = int(input())
	if n == 0: break
	tbl = {}
	for _ in range(n):
		p = list(map(int, input().split()))
		id = p[0]
		del p[0]
		sum = k = 0
		for f in range(9):
			s = p[k]
			if s == 10:
				sum += 10+p[k+1]+p[k+2]
				k += 1
			else:
				s += p[k+1]
				sum += s
				k += 2
				if s == 10: sum += p[k]
		sum += p[k] + p[k+1]
		if p[k] == 10 or p[k]+p[k+1] == 10: sum += p[k+2]
		tbl[id] = sum
	ans = sorted(tbl.items(), key=lambda x:(x[1],-x[0]), reverse=True)
	for i in ans: print(*i)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0152

"""
import sys
from sys import stdin
input = stdin.readline


def bowling_score(data):
    name_id = data[0]
    data = data[1:]

    frame = 1
    scores = [0] * 11

    while frame <= 10:
        if data[0] == 10:
            scores[frame] = data[0] + data[1] + data[2]
            data = data[1:]
            frame += 1
        elif data[0] + data[1] == 10:
            scores[frame] = data[0] + data[1] + data[2]
            data = data[2:]
            frame += 1
        else:
            scores[frame] = data[0] + data[1]
            data = data[2:]
            frame += 1
    return name_id, sum(scores[1:])


def main(args):
    while True:
        m = int(input())
        if m == 0:
            break
        results = []
        for _ in range(m):
            data = [int(x) for x in input().split()]
            name_id, score = bowling_score(data)
            results.append([-score, name_id])

        results.sort()
        for s, i in results:
            print(i, -s)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: while True:
    n = int(input())
    if n == 0: break
    num = []
    for i in range(n):
        score = list(map(int, input().split()))
        score.extend([0,0,0])
        cnt = 0
        flag = 0
        flame = 1
        for j in range(len(score[1:])):
            cnt+=score[j+1]
            if flame >= 10:
                pass
            elif score[j+1] == 10 and flag == 0:
                cnt+=score[j+2]+score[j+3]
                flame+=1
            elif score[j+1]+score[j]==10 and flag == 1:
                cnt+=score[j+2]
                flag = 0
                flame+=1
            elif flag == 1:
                flag = 0
                flame+=1
            elif flag == 0:
                flag = 1
        num.append([score[0], cnt])
    for i in sorted(num, key = lambda x: (-x[1], x[0])):
        print(*i)