#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
using namespace std;

int calc(vector<int> v) {
	v.push_back(0);
	int ret = 0;
	int k = 0, p1, p2, p3;
	for (int i=0; i<10; ++i) {
		p1 = 0, p2 = 0, p3 = 0;
		p1 = v[k++];
		if (i == 9) {
			p2 = v[k++];
			if (p1 == 10 || p1 + p2 == 10) p3 = v[k++];
		} else {
			if (p1 == 10) {
				ret += v[k] + v[k+1];
			} else {
				p2 = v[k++];
				if (p1 + p2 == 10) {
					ret += v[k];
				}
			}
		}
		ret += p1 + p2 + p3;
	}
	return ret;
}

int main() {
	int m;
	while (cin >> m, m) {
		cin.ignore();
		vector<pair<int,int>> res;
		string s;
		int idx, t;
		for (int i=0; i<m; ++i) {
			getline(cin, s);
			stringstream ss(s);
			ss >> idx;
			vector<int> score;
			while (ss >> t) {
				score.push_back(t);
			}
			res.push_back(make_pair(-calc(score), idx));
		}
		sort(res.begin(), res.end());
		for (int i=0; i<(int)res.size(); ++i) {
			cout << res[i].second << " " << -res[i].first << endl;
		}
	}
	return 0;
}