#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<pair<int,int> > v;
		rep(i,n)
		{
			
			vector<pair<int,int> > temp;
			vector<string> data;
			int num;
			cin >> num;
		
			int cnt = 0;
			while(cnt != 10)
			{
				int a,b,last;
				cin >> a;

				if(a == 10)
				{
					temp.push_back(make_pair(a,0));
					cnt++;
					data.push_back("st");

					if(cnt == 10)
					{
						int t;
						cin >> t;

						if(t == 10)
						{
							int t2;
							cin >> t2;
							temp.push_back(make_pair(t,0));
							data.push_back("st");

							temp.push_back(make_pair(t2,0));
							data.push_back("st");
							
						}
						else
						{
							int t2;
							cin >> t2;
							temp.push_back(make_pair(t,t2));
							if(t+t2 == 10) data.push_back("sp");
							else data.push_back("no");
						}
					}
				}
				else
				{
					cin >> b;
					temp.push_back(make_pair(a,b));
					cnt++;

					if(a + b == 10)
					{
						data.push_back("sp");
						
						if(cnt == 10)
						{
							int t;
							cin >> t;
							temp.push_back(make_pair(t,0));
							data.push_back("l");
						}
					}
					else
					{
						data.push_back("no");
					}
				}
			}

			int ans = 0;
			rep(i,10)
			{
				if(data[i] == "no")
				{
					ans += temp[i].first + temp[i].second;
				}
				else if(data[i] == "sp")
				{
					ans += temp[i].first + temp[i].second + temp[i+1].first;
				}
				else if(data[i] == "st")
				{
					ans += temp[i].first + temp[i].second + temp[i+1].first + temp[i+1].second;
					if(data[i+1] == "st") ans += temp[i+2].first;
				}

			}	
			v.push_back(make_pair(ans,num));
		}

		sort(v.begin(),v.end(),greater<pair<int,int> >());

		rep(i,v.size())
		{
			cout << v[i].second << " " << v[i].first << endl;
		}
	}
	return 0;
}	