#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Student{
	int id,score;
};

struct Data{
	int score,first,second;
	bool strike,spare;
};

int main(){

	int num,tmp,index,pre_score;
	char buf[120];
	Student students[40];
	Data game_data[12];
	bool First;

	while(true){
		scanf("%d",&num);
		if(num == 0)break;

		for(int i = 0; i < 40; i++){
			students[i].score = 0;
		}

		getchar();

		for(int i = 0; i < num; i++){
			for(int k=0; k <= 11; k++){
				game_data[k].score = 0;
				game_data[k].first = 0;
				game_data[k].second = 0;
				game_data[k].strike = false;
				game_data[k].spare = false;
			}

			First = true;

			fgets(buf,120,stdin);

			tmp = 0;
			index = 0;
			pre_score = -1;
			for(int k = 0; buf[k] != '\n'; k++){
				if(buf[k] >= '0' && buf[k] <= '9'){
					tmp = 10*tmp + (buf[k] - '0');

					if(buf[k+1] == '\n'){
						if(pre_score == -1){
							game_data[index].first = tmp;
							game_data[index].score = tmp;
						}else{
							game_data[index].second = tmp;
							game_data[index].score = pre_score + tmp;
						}
					}
				}else{
					if(First){
						students[i].id = tmp;
						First = false;
					}else{

						if(pre_score == -1){
							game_data[index].first = tmp;
							if(tmp == 10){
								game_data[index].score = 10;
								game_data[index].strike = true;
								index++;
							}else{
								pre_score = tmp;
							}

						}else{
							game_data[index].second = tmp;
							game_data[index].score = pre_score + tmp;
							if(pre_score + tmp == 10){
								game_data[index].spare = true;
							}

							index++;

							pre_score = -1;
						}
					}

					tmp = 0;
				}
			}

			for(int k = 0; k <= 11; k++){
				students[i].score += game_data[k].score;
					if(k <= 8 && game_data[k].spare == true){
					students[i].score += game_data[k+1].first;
				}

				if(k <= 8 && game_data[k].strike == true){
					students[i].score += game_data[k+1].first;
					if(game_data[k+1].first == 10){
						students[i].score += game_data[k+2].first;
					}else{
						students[i].score += game_data[k+1].second;
					}
				}
			}
		}

		for(int i = 1; i <= num-1; i++){
			for(int k = num-1; k >= i; k--){
				if(students[k].score > students[k-1].score)swap(students[k],students[k-1]);
				else if(students[k].score == students[k-1].score && students[k].id < students[k-1].id)swap(students[k],students[k-1]);
			}
		}

		for(int i=0; i < num; i++){
			printf("%d %d\n",students[i].id,students[i].score);
		}
	}

    return 0;
}