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: 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.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):
			if p[k] == 10:
				sum += p[k]+p[k+1]+p[k+2]
				k += 1
			else:
				sum += p[k]+p[k+1]
				if p[k]+p[k+1] == 10: sum += p[k+2]
				k += 2
		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: # from sys import exit

while(True):
    N = int(input())
    if N == 0:
        exit()
    score = [[] for _ in range(N)]
    ids = [0 for _ in range(N)]
    for i in range(N):
        score[i] = [int(n) for n in input().split()]
        ids[i] = score[i][0]
        cnt = 0 # フレームのための
        frame = 0 # 10フレームの処理
        sum = 0
        ans = 0
        # ストライクなら二回分、スペアなら一回分
        double = 0
        triple = 0
        for s in score[i][1:]:
            if triple and frame != 10:
                ans += 3*s
                # if i == 1:print(3*s, frame)
                triple -= 1
                double -= 1
            elif double and frame != 10:
                ans += 2*s
                # if i == 1:print(2*s, frame)
                double -= 1
            else:
                # if i == 1:print(s, frame)
                ans += s
            sum += s
            cnt += 1

            # ストライク
            if cnt == 1 and s == 10:
                cnt = 0
                sum = 0
                if double:
                    triple += 1
                    double = 2
                else:
                    double += 2
                frame+=1
            # スペア
            elif cnt == 2 and sum == 10:
                if double:
                    triple += 1
                else:
                    double += 1
            # フレームのリセット
            if (cnt == 2):
                # print("AAA" + str(sum), cnt)
                cnt = 0
                sum = 0
                frame+=1
        score[i] = (ids[i], ans)
    score = sorted(score, key=lambda x: x[0])
    score = sorted(score, key=lambda x: -x[1])
    n = len(score)
    for s in score:
        if n:
            print(s[0], s[1], end=" \n")
        else:
            print(s[0], s[1])

Python: def score(x):
    s=0;t=1
    for _ in[0]*10:
        a=2;b=3
        if x[t]==10:a=1
        elif x[t]+x[t+1]!=10:b=2
        s+=sum(x[t:t+b]);t+=a
    return x[0],s

while 1:
    n=int(input())
    if n==0:break
    A=sorted([score(map(int,input().split())) for _ in [0]*n])
    for a,b in sorted(A,key=lambda x:-x[1]):print(a,b)