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 get_point(info):
  info.reverse()
  acc = 0
  NORMAL, SPARE, STRIKE, DOUBLE = 0, 1, 2, 3
  flag = NORMAL
  game_num = 0
  while info:
    if game_num != 9:
      down_num1 = info.pop()
      if down_num1 != 10:
        down_num2 = info.pop()
        if flag == SPARE:
          acc += down_num1 * 2 + down_num2
        elif flag == STRIKE:
          acc += down_num1 * 2 + down_num2 * 2
        elif flag == DOUBLE:
          acc += down_num1 * 3 + down_num2 * 2
        else:
          acc += down_num1 + down_num2
        
        if down_num1 + down_num2 == 10:
          flag = SPARE
        else:
          flag = NORMAL
      
      else:
        if flag in (SPARE, STRIKE):
          acc += down_num1 * 2
        elif flag == DOUBLE:
          acc += down_num1 * 3
        else:
          acc += down_num1
        if flag in (STRIKE, DOUBLE):
          flag = DOUBLE
        else:
          flag = STRIKE
      game_num += 1

    else:
      down_num1, down_num2 = info.pop(), info.pop()
      if flag == SPARE:
        acc += down_num1 * 2 + down_num2
      elif flag == STRIKE:
        acc += down_num1 * 2 + down_num2 * 2
      elif flag == DOUBLE:
        acc += down_num1 * 3 + down_num2 * 2
      else:
        acc += down_num1 + down_num2
      if info:
        acc += info.pop()
  
  return acc

while True:
  m = int(input())
  if m == 0:
    break
  score = [list(map(int, input().split())) for _ in range(m)]
  score_mp = [(info[0], get_point(info[1:])) for info in score]
  score.mpsort()
  score_mp.sort(key=lambda x:-x[1])
  for pair in score_mp:
    print(*pair)

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(1, 11):
			if f == 10:
				sum += p[k] + p[k+1]
				if p[k] == 10 or p[k]+p[k+1] == 10: sum += p[k+2]
				break
			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]
		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
# Your code here!

class Player:
    
    id = 0
    score = 0
    def __init__(self, id, score):
        self.id = id
        self.score = score
        
    def __lt__(self, other):
        if self.score == other.score:
            return self.id < other.id
        else:
            return self.score > other.score


while True:
    N = int(input())
    if N == 0:
        break
    
    players = []
    
    for l in range(N):
        line = [int(i) for i in input().split()]
        line.append(0)
        line.append(0)
        score = 0
        round = 0
        i = 1
        while round < 10:
            if round < 9:
                if line[i] < 10:
                    if line[i] + line[i+1] < 10:
                        score += line[i] + line[i+1]
                    else:
                        score += line[i] + line[i+1] + line[i+2]
                    i += 2
                    round += 1
                else:
                    score += line[i] + line[i+1] + line[i+2]
                    i += 1
                    round += 1
            else:
                score += line[i] + line[i+1] + line[i+2]
                round += 1
        
        players.append(Player(line[0], score))
    
    players.sort()
    
    for i in range(N):
        print(players[i].id, players[i].score)

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: 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], 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 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(list(map(int,input().split()))) for _ in [0]*n])
    for a,b in sorted(A,key=lambda x:-x[1]):print(a,b)

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 = int(p.pop(0))
		sum = 0
		for f in range(10-1):
			if p[0] == 10:
				sum += p[0]+p[1]+p[2]
			else:
				sum += p[0]+p[1]
				if p[0]+p[1] == 10: sum += p[2]
				p.pop(0)
			p.pop(0)
		sum += p[0]+p[1]
		if p[0] == 10 or p[0]+p[1] == 10: sum += p[2] #10番フレーム		
		tbl[id] = sum
	for i in sorted(tbl.items(), key=lambda x:(x[1],-x[0]), reverse=True): print(*i)