#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<pair<int, int> > v;
		
		for (int i = 0; i < n; i++){
			int stNo;
			scanf("%d", &stNo);
			
			int frame = 0;
			int frameScore[10] = {0}, remain[10] = {0};
			int prev = -1;
			int ct = 0;
			while (frame < 10){
				int pin;
				scanf("%d", &pin);
				frameScore[frame] += pin;
				
				if (frame == 9){
					if (ct == 1 && frameScore[frame] < 10) frame++;
					else if (ct == 2) frame++;
					ct++;
				}
				
				for (int j = 0; j < 10; j++){
					if (remain[j]){
						frameScore[j] += pin;
						remain[j]--;
					}
				}
				
				if (frame < 9){
					if (prev + pin == 10){
						remain[frame] = 1;
						frame++;
						prev = -1;
					}
					else if (pin == 10){
						remain[frame] = 2;
						frame++;
						prev = -1;
					}
					else if (~prev){
						frame++;
						prev = -1;
					}
					else if (prev == -1) prev = pin;
				}
			}
			
			int sum = 0;
			for (int j = 0; j < 10; j++) sum += frameScore[j];
			v.push_back(make_pair(-sum, stNo));
		}
		
		sort(v.begin(), v.end());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", v[i].second, -v[i].first);
		}
	}
	
	return (0);
}