#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Player {
public:
	int id;
	vector<int> g[10];
	vector<int> idx[10];
	vector<int> s;
	int h[10] = {};
	Player(int id, vector<int> s) :id(id), s(s) {
		int game = 0;
		int cnt = 0;
		rep(i, 0, s.size()) {
			assert(game < 10);
			if (cnt == 0) {
				g[game].emplace_back(s[i]);
				idx[game].emplace_back(i);
				if (s[i] == 10) {
					if (game == 9) {
						g[game].emplace_back(s[i + 1]);
						g[game].emplace_back(s[i + 2]);
						idx[game].emplace_back(i + 1);
						idx[game].emplace_back(i + 2);
						break;
					}
					h[game] = 2;
					game++;
				}
				else cnt++;
			}
			else if (cnt == 1) {
				g[game].emplace_back(s[i]);
				idx[game].emplace_back(i);
				if (s[i] + s[i - 1] == 10) {
					if (game == 9) {
						g[game].emplace_back(s[i + 1]);
						idx[game].emplace_back(i + 1);
						break;
					}
					h[game] = 1;
				}
				game++;
				cnt = 0;
			}
		}
	}
	bool operator<(Player that) {
		int a = score(), b = that.score();
		return a == b ? id > that.id:a < b;
	}
	int score() {
		int ret = 0;
		int gs[10] = {};
		rep(i, 0, 10) {
			gs[i] = accumulate(all(g[i]), 0);
			ret += gs[i];
		}
		dump(ret);
		rep(i, 0, 10) {
			if (h[i] >= 1)ret += s[idx[i + 1][0]];
			if (h[i] == 2)ret += s[idx[i + 1][0] + 1];
		}
		dump(ret);
		return ret;
	}
};

//delimiter??£?¶?????????????delimiter?????????
vector<string> split(const string& input, const char& delimiter) {
	vector<string> ret;
	string w;
	for (const char& c : input) {
		if (c == delimiter) {
			if (w.size())	ret.emplace_back(w);
			w.clear();
		}
		else w += c;
	}
	if (w.size())	ret.emplace_back(w);
	return ret;
}

signed main() {
	for (int m; cin >> m&&m;) {
		vector<Player> v;
		cin.ignore();
		rep(i, 0, m) {
			string s;
			getline(cin, s);
			vector<string> v2 = split(s, ' ');
			int id = stoi(v2[0]);
			vector<int> v3;
			rep(j, 1, v2.size())v3.emplace_back(stoi(v2[j]));
			v.emplace_back(id, v3);

			rep(k, 0, 10) {
				dumpc(v[i].g[k]);
			}
			dumpc(v[i].h);
		}
		sort(all(v));
		rrep(i, 0, v.size()) {
			cout << v[i].id << " " << v[i].score() << endl;
		}
	}
	return 0;
}