Go: package main

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

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: # 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])
    for s in score:
        print(s[0], s[1])

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_mp.sort()
  score_mp.sort(key=lambda x:-x[1])
  for pair in score_mp:
    print(*pair)

Python: FIRST = 1
SECOND = 2

while True:

    score_count = int(input())

    if score_count == 0:
        break

    score_list = []

    for _ in range(score_count):

        total_score = 0
        score_data = [int(item) for item in input().split(" ")]

        last_score = 0
        frame_count = 1
        ball_state = FIRST

        for index, score in enumerate(score_data[1:], 1):

            if frame_count == 10:
                total_score += sum(score_data[index:])
                break

            if last_score + score == 10:
                if ball_state == FIRST:
                    # ストライク
                    total_score += score + score_data[index + 1] + score_data[index + 2]
                else:
                    # スペア
                    total_score += score + score_data[index + 1]
                    ball_state = FIRST
                    last_score = 0

                frame_count += 1

            else:
                # 通常
                total_score += score

                if ball_state == FIRST:
                    ball_state = SECOND
                    last_score = score
                else:
                    ball_state = FIRST
                    last_score = 0
                    frame_count += 1

        score_list.append([score_data[0], total_score])

    score_list.sort(key=lambda x: (-x[1], x[0]))
    output = [str(id) + " " + str(score) for id, score in score_list]
    print("\n".join(output))

Python: while 1:
    m = int(input())
    if m == 0:
        break

    result = []
    for _ in range(m):
        datas = list(map(int, input().split()))
        student = datas.pop(0)

        score = 0
        frame = 1
        while 1:
            if frame == 10:
                while datas != []:
                    score += datas.pop(0)
                break

            first = datas.pop(0)
            if first == 10:
                score += 10 + datas[0] + datas[1]
            else:
                second = datas.pop(0)
                if first + second == 10:
                    score += 10 + datas[0]
                else:
                    score += first + second
            frame += 1

        result.append([student, score])

    result.sort()
    result = sorted(result, reverse=True, key=lambda x: x[1])
    for res in result:
        print(res[0], res[1])