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++: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

template<class Istr>
vector<int> separated_str(Istr& istr, char delim){
    std::string str;
    vector<int> res;
    while(std::getline(istr, str, delim)){
        res.push_back(stoi(str));
    }
    return res;
}

signed main() {
    int M;
    while(cin >> M, M) {
        vector<int> ids, scores, ord;
        string s;
        cin.ignore();
        for(int i=0; i<M; i++) {
            getline(cin, s);
            stringstream ss(s);
            auto v = separated_str(ss, ' ');

            int id = v[0];
            int score = 0, pre1 = 0, pre2 = 0, t = 1, p = 0, f = 1;
            for(size_t k=1; k<v.size(); k++) {
                score += v[k];
                score += (pre1 + pre2) * v[k];

                pre1 = pre2;
                pre2 = 0;
                int pf = f, pt = t;
                if(t == 1 and v[k] == 10) {
                    if(f < 10) pre2++;
                    t = 1;
                    f++;
                }
                else if(t == 2 and p + v[k] == 10) {
                    if(f < 10) pre1++;
                    t = 1;
                    f++;
                }
                else {
                    t++;
                    if(f < 10 and t == 3) f++, t = 1;
                }
                p = v[k];
                // fprintf(stderr, "# f = %lld, t = %lld, %lld\n", pf, pt, score);
            }
            ids.push_back(id);
            scores.push_back(score);
            ord.push_back(i);
        }
        sort(ord.begin(), ord.end(), [&](int x, int y) {
                if(scores[x] != scores[y]) return scores[x] > scores[y];
                return ids[x] < ids[y];
            });

        for(int i=0; i<M; i++) {
            cout << ids[ ord[i] ] << " " << scores[ ord[i] ] << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
pair<int,int> d[40];
int cnt,sparecnt,throwcnt,plus[2];
int numcnt;
void Sc(int u){
	if(numcnt>9)plus[0]--;
	if(numcnt>10)plus[0]--;
	d[u].first+=cnt*plus[0];
	plus[0]=plus[1];
	plus[1]=1;
	throwcnt++;
	sparecnt+=cnt;
	if(throwcnt==2){
		if(sparecnt==10){
			plus[0]++;
		}
		throwcnt=0;
		sparecnt=0;
		numcnt++;
	}
	if(cnt==10){
		plus[0]++;
		plus[1]++;
		throwcnt=0;
		sparecnt=0;
		numcnt++;
	}
	cnt=0;
}
int main(){
	int m;
	while(true){
	cin>>m;
	if(!m)break;
	string s;
	for(int u=0;u<m;u++){
		cin>>d[u].second;
		getline(cin,s);
		d[u].second=10000-d[u].second;
		d[u].first=0;
		cnt=0,sparecnt=0,throwcnt=-1,plus[0]=1,plus[1]=1;
		numcnt=0;
		for(int i=0;i<s.size();i++){
			if(s[i]==' '){
				Sc(u);
			}
			else{
				cnt*=10;
				cnt+=s[i]-'0';
			}
		}
		Sc(u);
	}
	sort(d,d+m);
	for(int i=m-1;i>=0;i--){
		cout<<10000-d[i].second<<" "<<d[i].first<<endl;
	}
	}
	return 0;
}

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

class Student{
public:
  int score, no;
  Student() : score(0) {}
  bool operator <(const Student &s) const{
    if(score != s.score) return score > s.score;
    return no < s.no;
  }
};

main() {
  while(1) {
    int m;
    set<Student> S;
    cin >> m;
    if(m == 0) break;
    for(int i = 0; i < m; i++) {
      int result[10];
      Student tmp;
      int a, b, c;
      cin >> tmp.no;
      for(int i = 0; i < 9; i++) {
	cin >> a;
	tmp.score += a;
	if(i-1 >= 0 && result[i-1] >= 1) tmp.score += a;
	if(i-2 >= 0 && result[i-2] == 2 && result[i-1] == 2) tmp.score += a;

	if(a == 10) {
	  result[i] = 2;
	  continue;
	}
	cin >> b;
	tmp.score += b;
	if(i-1 >= 0 && result[i-1] == 2) tmp.score += b;
	if(a+b == 10) {
	  result[i] = 1;
	  continue;
	}
	result[i] = 0;
      }

      cin >> a >> b;
      c = 0;
      if(a+b >= 10) {
	cin >> c;
      }
      if(result[8] >= 1) tmp.score += a;
      if(result[7] == 2 && result[8] == 2) tmp.score += a;
      if(result[8] == 2) tmp.score += b;
      tmp.score += a+b+c;

      S.insert(tmp);
    }
    for(set<Student>::iterator it = S.begin();
	it != S.end(); it++) {
      cout << it->no << ' ' << it->score << endl;
    }
  }
}