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
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i = 0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int ROUND = 10, STR = 2, SP = 1;
typedef pair<int, int> pp;
int main()
{
    int m;
    while(cin >> m && m)
    {
        vector<pp> po;
        rep(k,m)
        {
            int snum, t;
            cin >> snum;

            vector<int> th_pin;
            int fir, sec;
            for(int i_f = 0;i_f < 9; i_f++)
            {
                cin >> fir;
                th_pin.push_back(fir);
                if(fir == 10){ continue;}
                cin >> sec;
                th_pin.push_back(sec);
            }
            cin >> fir;
            if(fir == 10)
            {
                cin >> sec >> t;
                th_pin.push_back(fir); th_pin.push_back(sec);th_pin.push_back(t);
            }
            else
            {
                cin >> sec;
                th_pin.push_back(fir); th_pin.push_back(sec);
                if(fir + sec == 10){cin >>t ; th_pin.push_back(t);}
            }
            //REP(th_pin.size()) cout << i << "th " << th_pin[i] << endl;
            int f_point[10] = {};
            int th = 0;
            for(int i_f = 0;i_f < 10; i_f++)
            {
                if(th_pin[th] == 10)
                    f_point[i_f] = th_pin[th] + th_pin[th+1] + th_pin[th+2];
                else if(th_pin[th] + th_pin[th+1] == 10)
                {
                    f_point[i_f] = th_pin[th] + th_pin[th+1] + th_pin[th+2];
                    th++;
                }
                else
                {
                    f_point[i_f] = th_pin[th] + th_pin[th+1];
                    th++;
                }
                th++;
            }
            int point = 0;
            REP(10) point += f_point[i];
            po.push_back(pp(-point, snum));
        }
        sort(all(po));

        REP(po.size()) cout << po[i].second << " " << -po[i].first << endl;

    }
    return 0;
}

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

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		int id;
		vector<P> vec;
		for(int ii = 0;ii < n;ii++){
			int add[21] = {},score[21] = {},sum = 0,frame = 0,tou = 1;
			cin >> id;
			for(int i = 0;frame < 10;i++){
				cin >> score[i];
				//cout << score[i] << " " << frame << " " << tou << endl;
				add[i]++;
				if(tou == 1 && score[i] == 10){
					if(frame != 9){
						frame++;
						add[i + 1]++;
						add[i + 2]++;
					}else{
						tou++;
					}
				}else if(tou == 2 && score[i] + score[i - 1] >= 10){
					if(frame == 9) tou = 3;
					else{
						frame++;
						add[i + 1]++;
						tou = 1;
					}
				}else if(tou == 2){
					frame++;
					tou = 1;
				}else if(tou == 3) frame++;
				else tou++;
			}
			for(int i = 0;i < 21;i++){
				sum += score[i] * add[i];
			}
			vec.push_back(P(sum,-id));
		}
		sort(vec.begin(),vec.end(),greater<P>());
		for(int i = 0;i < n;i++){
			cout << -vec[i].second << " " << vec[i].first << endl;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

struct frame {
	int type;
	vector<int>pins;
	int score;
	frame():type(0), pins(), score(0){

	}
};
int getscore() {
	vector<frame>frames(10);
	int now = 0;
	int num = 0;
	int sum = 0;
	vector<pair<int, int>>ps;
	bool flag = false;
	while (1) {
		int n; cin >> n;
		if (now != 9) {
			if (num == 0) {
				frames[now].pins.push_back(n);
				sum += n;
				if (sum == 10) {
					now++;
					num = 0;
					sum = 0;
					ps.push_back(make_pair(2, n));
				}
				else {
					num++;
					ps.push_back(make_pair(0, n));
				}
			}
			else if (num == 1) {
				frames[now].pins.push_back(n);
				sum += n;
				if (sum == 10) {
					ps.push_back(make_pair(1, n));
				}
				else {
					ps.push_back(make_pair(0, n));
				}
				sum = 0;
				num = 0;
				now++;
			}
		}
		else {
			if (num == 0) {
				sum += n;
				if (sum == 10) {
					sum = 0;
					ps.push_back(make_pair(0, n));
					flag = true;
				}
				else {
					ps.push_back(make_pair(0, n));
				}
			}
			else if (num == 1) {
				sum += n;
				if (sum == 10) {
					sum = 0;
					ps.push_back(make_pair(0, n));
					flag = true;
				}
				else {
					ps.push_back(make_pair(0, n));
				}
				if (!flag)break;
			}
			else if (num == 2) {
				sum += n;
				ps.push_back(make_pair(0, n));
				break;
			}
			num++;
		}
		
	}
	int score = 0;
	for (int i = 0; i < ps.size(); ++i) {
		for (int j = i; j <= i + ps[i].first; ++j) {
			score += ps[j].second;
		}
	}
	return score;
}

int main() {
	
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, int>>ps;
		for (int i = 0; i < N; ++i) {
			int num; cin >> num;
			int ans = getscore();
			ps.emplace_back(ans, 10000 - num);
		}
		sort(ps.begin(), ps.end(), greater<pair<int, int>>());
		for (auto p : ps) {
			cout << 10000 - p.second << " " << p.first << endl;
		}
	}
	return 0;
}