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 <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


II solve( int no, VI A ) {
    VI F(10, 0), S(10, 0), C(10, 0);
    VI T(10, 0);
    int t = 0;
    for ( int i = 0; i < 10; ++ i ) {
        F[i] = 0, S[i] = 0, C[i] = 0;
        if ( i == 9 ) {
            F[i] = A[t++];
            S[i] = A[t++];
            C[i] = 0;
            if ( F[i] == 10 || S[i] == 10 || F[i] + S[i] == 10 ) C[i] = A[t++];
        } else {
            if ( A[t] == 10 ) {
                F[i] = A[t++];
            } else {
                F[i] = A[t++];
                S[i] = A[t++];
            }
        }
    }

    for ( int i = 0; i < 10; ++ i ) {
        T[i] = F[i] + S[i] + C[i];
    }

    int addScore = 0;
    for ( int i = 0; i < 9; ++ i ) {
        if ( F[i] == 10 ) {
            if ( i < 8 ) {
                if ( F[i+1] == 10 ) {
                    addScore += 10 + F[i+2];
                } else {
                    addScore += F[i+1] + S[i+1];
                }
            } else if ( i == 8 ) {
                addScore += F[9] + S[9];
            }
        } else if ( F[i] + S[i] == 10 ) {
            addScore += F[i+1];
        }
    }
    return II( accumulate( T.begin(), T.end(), 0 ) + addScore, no );
}

int main() {
    string line;
    while ( getline( cin, line ) ) {
        if ( line == "0" ) break;
        ISS iss( line );
        int n;
        iss >> n;
        VII scores( n );
        for ( int i = 0; i < n; ++ i ) {
            getline( cin, line );
            ISS iss( line );
            int no;
            iss >> no;
            int a;
            VI A;
            while ( iss >> a ) A.push_back( a );
            scores[i] = solve( no, A );
        }
        sort( scores.rbegin(), scores.rend() );
        for ( int i = 0; i < n; ++ i ) {
            for ( int j = i + 1; j < n; ++ j ) {
                if ( scores[i].first == scores[j].first ) {
                    if ( scores[i].second > scores[j].second ) {
                        swap( scores[i], scores[j] );
                    }
                }
            }
        }
        for ( int i = 0; i < n; ++ i ) {
            cout << scores[i].second << " " << scores[i].first << endl; 
        }
    }
    return 0;
}

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

struct score_board {
	int id;
	int score;
	int frames[32];
	int throws[32];

	score_board() {
		id = -1; score = -1;
		for(int i = 0; i < 32; i++) {
			frames[i] = -1;
			throws[i] = -1;
		}
	}

	int set_score() {
		if(score != -1)
			return score;
		score = 0;

		for(int f = 0; f < 10; f++) {
			score += max(0, throws[frames[f*2]]) + max(0, throws[frames[f*2 + 1]]);
			if(max(0, throws[frames[f*2]]) == 10) {
				score += max(0, throws[frames[f*2] + 1]) + max(0, throws[frames[f*2] + 2]);
			}
			else if(max(0, throws[frames[f*2]]) + max(0, throws[frames[f*2 + 1]]) == 10) {
				score += max(0, throws[frames[f*2 + 1] + 1]);
			}
		}

		return score;
	}

	bool operator<(const score_board& b) const {
		if(score == b.score)
			return id > b.id;
		return score < b.score;
	}
};

istream& operator>>(istream& istr, score_board& sb) {
	string s;
	int count = 0;
	istr >> sb.id;
	getline(istr, s);
	stringstream sstr(s);
	
	int n = 0;
	int frame_count = 0;
	int throw_count = 0;
	int pin = 0;
	while(sstr >> sb.throws[n]) {
		pin += sb.throws[n];
		sb.frames[frame_count * 2 + throw_count] = n;
		if(pin == 10 || (throw_count > 0 && frame_count < 9)) {
			pin = 0;
			throw_count = 0;
			frame_count++;
		}
		else
			throw_count++;
		n++;
	}
	sb.set_score();

	/*
	cout << "id:" << sb.id << endl;
	for(int i = 0; i < 10; i++) {
		cout << ":" << sb.throws[sb.frames[i*2]] << " " << sb.throws[sb.frames[i*2 + 1]];
	}
	cout << endl;
	*/

	return istr;
}

int main() {
	int n;
	while(cin >> n, n) {
		vector<score_board> in;
		for(int i = 0; i < n; i++) {
			score_board tmp;
			cin >> tmp;
			in.push_back(tmp);
		}
		sort(in.rbegin(), in.rend());
		for(int i = 0; i < in.size(); i++) {
			cout << in[i].id << " " << in[i].score << endl;
		}
	}
	return 0;
}