#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct bp {
	int nb, pt;

	bool operator < (const bp & rhs) const {
		return pt > rhs.pt || (pt == rhs.pt && nb < rhs.nb);
	}
};

int main()
{	
	int n;

	cin >> n;

	while (n > 0) {
		vector<bp> a(n);

		for (int i = 0; i < n; i++) {
			cin >> a[i].nb;

			vector<int> b;

			while (cin.get() != '\n') {
				int t;
				cin >> t;
				b.push_back(t);
			}

			a[i].pt = 0;
			int j = 0, fl = 1;
			while (j < b.size()) {
				if (fl == 10) {
					a[i].pt += b[j];
					j++;
				}
				else {
					fl++;
					a[i].pt += b[j] + b[j + 1];

					if (b[j] == 10 || b[j] + b[j + 1] == 10)
						a[i].pt += b[j + 2];

					if (b[j] == 10)
						j++;
					else
						j += 2;
				}
 			}
		}

		sort(a.begin(), a.end());

		for (int i = 0; i < n; i++)
			cout << a[i].nb << " " << a[i].pt << endl;

		cin >> n;
	}

	return 0;
}

