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
}

C++: #include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <sstream>
using namespace std;

int main(){
  int m;
  while(cin >> m, m){
    vector<string> I(m);
    vector<int> S(m,0);
    for(int i = 0; i < m; ++i){
      cin >> I[i];
      vector<int> t;
      for(int j = 0; j < 20; ++j){
        int s;
        cin >> s;
        if(j < 18 and s == 10) ++j;
        t.push_back(s);
      }
      if(t[t.size()-1]+t[t.size()-2] >= 10){
        int s;
        cin >> s;
        t.push_back(s);
      }
      int l = 0;
      for(size_t j = 0; j < t.size(); ++j){
        int tmp = t[j], k = 0;
        ++l;
        if(tmp < 10 and j+1 < t.size()) tmp += t[++j], ++k;
        if(l < 10 and tmp == 10){
          if(j+1 < t.size()) S[i] += t[j+1];
          if(k == 0 and j+2 < t.size()) S[i] += t[j+2];
        }
        S[i] += tmp;
      }
      
    }
    vector<pair<int,int>> V;
    for(int i = 0; i < m; ++i)
      V.emplace_back(S[i],i);
    sort(V.rbegin(), V.rend());
    for(auto p : V)
      cout << I[p.second] << " " << p.first<< endl;
  }
}