#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()

typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef pair<int, ppi> pipp;


int main()
{
	int m;
	while (cin >> m&&m)
	{
		vector<pi> a;
		for (int r = 0; r < m; r++)
		{
			int num; cin >> num;
			int score = 0;
			int k[21], j[21];
			memset(k, -1, sizeof(k));
			memset(j, -1, sizeof(j));
			for (int i = 0; i < 18; i += 2)
			{
				cin >> k[i];
				if (k[i] == 10)
				{
					j[i] = 2;
				}
				else
				{
					cin >> k[i + 1];
					if (k[i] + k[i + 1] == 10)
					{
						j[i + 1] = 1;
					}
				}
			}
			cin >> k[18] >> k[19];
			if (k[18] + k[19] >= 10)
			{
				cin >> k[20];
			}
			for (int i = 0; i < 21; i++)
			{
				if (j[i] == 1)
				{
					k[i] += k[i + 1];
				}
				else if (j[i] == 2)
				{
					k[i] += k[i + 2];
					if (k[i + 3] == -1)
					{
						k[i] += k[i + 4];
					}
					else
					{
						k[i] += k[i + 3];
					}
				}
			}

			for (int i = 0; i < 21; i++)
			{
				score += max(0, k[i]);
			}
			a.push_back(pi(score, num));
		}
		sort(a.begin(), a.end());
		reverse(a.begin(), a.end());
		bool che = true;
		while (che)
		{
			che = false;
			for (int i = 1; i < m; i++)
			{
				if (a[i].second < a[i - 1].second&&a[i].first == a[i - 1].first)
				{
					swap(a[i], a[i - 1]);
					che = true;
				}
			}

		}
		for (int i = 0; i < m; i++)
		{
			cout << a[i].second << " " << a[i].first << endl;
		}

	}
}