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 <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

enum{NONE,STRIKE,SPARE};

bool compare(pii a,pii b)
{
	return a.second==b.second?a.first<b.first:a.second>b.second;
}

int main()
{
	for(int m;cin>>m,m;){
		vector<pii> res;
		rep(i,m){
			int n; cin>>n;
			int score=0;
			int flg[2]={};
			rep(j,10){
				int p[3];
				if(j==9){
					rep(k,3){
						cin>>p[k];
						score+=p[k];
						if(flg[0]==STRIKE) score+=p[k];
						if(flg[1]) score+=p[k];
						flg[0]=flg[1];
						flg[1]=NONE;
						if(k==1 && p[0]+p[1]<10)
							break;
					}
				}
				else{
					int p[2];
					rep(k,2){
						cin>>p[k];
						score+=p[k];
						if(flg[0]==STRIKE) score+=p[k];
						if(flg[1]) score+=p[k];
						flg[0]=flg[1];
						if(k==0 && p[k]==10){
							flg[1]=STRIKE;
							break;
						}
						else if(k==1 && p[0]+p[1]==10)
							flg[1]=SPARE;
						else
							flg[1]=NONE;
					}
				}
			}
			res.push_back(mp(n,score));
		}
		sort(allof(res),compare);
		rep(i,res.size())
			cout<<res[i].first<<" "<<res[i].second<<endl;
	}
	
	return 0;
}

C++: #pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll m;
    while (cin >> m, m) {

        vector<ll> id(m);
        vector<ll> score(m, 0);

        REP(i, m) {
            cin >> id[i];
            ll sl = 0, r = 0;
            ll b = 0;
            vector<ll> pins(12, 0);
            vector<ll> fpin(12, 0);
            vector<bool> strike(12, false);
            vector<ll> term(12, 0);
            while (sl < 10) {
                ll x; cin >> x;
                r += x;
                if (b == 0) fpin[sl] = x;
                b++;
                if (r == 10 || b == 2) {
                    pins[sl] = r;
                    strike[sl] = r == 10 && b == 1;
                    b = 0;
                    r = 0;
                    sl++;
                }
            }
            if (pins[9] == 10) {
                ll x; cin >> x;
                fpin[10] = pins[10] = x;
                if (x == 10) {
                    strike[10] = true;
                } else {
                    cin >> x;
                    pins[10] += x;
                }
                if (pins[10] == 10 && strike[9]) {
                    cin >> x;
                    fpin[11] = pins[11] = x;
                    strike[11] = x == 10;
                }
            }
            REP(j, 9) {
                term[j] = pins[j];
                if (pins[j] == 10) {
                    if (strike[j]) {
                        if (j+1 < 12) {
                            term[j] += pins[j+1];
                            if (strike[j+1] && j+2 < 12) {
                                term[j] += fpin[j+2];
                            }
                        }
                    } else {
                        if (j+1 < 12) term[j] += fpin[j+1];
                    }
                }
            }
            term[9] = pins[9] + pins[10] + pins[11];
            score[i] = accumulate(ALL_OF(term), 0LL);
        }

        vector<ll> rank(m, 0);
        iota(ALL_OF(rank), 0LL);
        sort(ALL_OF(rank), [&](ll i, ll j) -> bool {
            if (score[i] != score[j]) {
                return score[i] > score[j];
            } else {
                return id[i] < id[j];
            }
        });

        REP(_i, m) {
            ll i = rank[_i];
            cout << id[i] << " " << score[i] << "\n";
        }

    }
    
}