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 <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

struct S
{
	int number,result;
	bool operator>(const S& other) const {
		return result == other.result ? number < other.number : result > other.result;
	}
};

int main()
{
	int m;
	while(cin >> m, m){
		cin.ignore();
		S s[41];
		for(int i = 0; i < m; ++i){
			int number;
			vector<int> v1,v2;
			string str;
			
			getline(cin,str);
			stringstream ss(str);
			ss >> number;
			int temp;
			while(ss >> temp){
				v1.push_back(temp);
			}			
			v2 = v1;
			
			int n = 1, point = 0, knock;
			int twice = 0;
			bool f = false;
			int prev = -1;
			for(int j = 0; j < v1.size(); ++j){
				if(prev == -1){
					if(v1[j] == 10){
						if(!(n >= 10)){
							v2[j + 1] += v1[j + 1];
							v2[j + 2] += v1[j + 2];
						}
						n++;
						prev = -1;
						continue;
					}
					prev = v1[j];
				} else {
					if(v1[j] + prev ==10){
						if(!(n >= 10))v2[j + 1] += v1[j + 1];
					}
					prev = -1;
					n += 1;
				}
			}
			point = accumulate(v2.begin(),v2.end(),0);
			s[i].number = number; s[i].result = point;
		}
		sort(s,s + m, greater<S>());
		for(int i = 0; i < m; ++i){
			cout << s[i].number << ' ' << s[i].result << endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

typedef pair<int,string> P;

vector<int> Point(string s){
  stringstream ss(s);
  int num;
  vector<int> v;

  while(ss >> num){
    v.push_back(num);
  }

  return v;
}

int getScore(string s){
  vector<int> a = Point(s);
  int len = (int)a.size();
  int score = 0 , sum = 0;
  int p = 0,n = 0;

  for(int i = 0 ; i < len ; i++){
    if(p >= 9){
      p++;
      score += a[i];
    }else{
      if(a[i] == 10){
	score += a[i] + a[i+1] + a[i+2];
	p++;
      }else{
	n++;
	sum += a[i];
	if(n == 2){
	  n = 0;
	  score += sum;
	  if(sum == 10){
	    score += a[i+1];
	  }
	  p++;
	  sum = 0;
	}
      }
    }
  }

  return -score;
}

int main(){
  int m;
  while(cin >> m ,m){
    vector<P> v;
    string pin;
    for(int i = 0 ; i < m ; i++){
      int score = 0;
      string num;
      cin >> num;
      getline(cin,pin);
      score = getScore(pin);
      v.push_back(P(score,num));
    }
    sort(v.begin(),v.end());
    for(int i = 0 ; i < m ; i++){
      cout << v[i].second << " " << -v[i].first << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main(){
	int m, n, t, p, f;
	stringstream ss;
	string s;
	vi v;
	while(cin>>m && m){
		cin.ignore();
		vector<pii> score(m);
		rep(j, m){
			getline(cin,s);
			ss.clear();
			ss<<s;
			ss>>n;
			v.clear();
			while(ss>>t) v.pb(t);
			//rep(i, v.size()) cout<<" "<<v[i];
			//cout<<endl;
			p = t = 0;
			f = 1;
			for(int i = 0; i < v.size() && f <= 10; i++, f++){
				t = v[i];
				if(t == 10){
					if(i+1<v.size())t += v[i+1];
					if(i+2<v.size())t += v[i+2];
					p += t;
					//<<t<<" "<<p<<endl;
					continue;
				}
				t+=v[i+1];
				i++;
				if(t == 10){
					if(i+1< v.size()) t+= v[i+1];
				}
				p+=t;
				//cout<<t<<" "<<p<<endl;
			}
			score[j] = mp(p, -n);
		}
		sort(rall(score));
		rep(i, m){
			cout<<-score[i].se<<" "<<score[i].fi<<endl;
		}
	}
}