#include<stdio.h>
#include<string.h>
#include<math.h>
int a,s[10000],d[10000][30],f,g[10000],h=0,j,i,k,z[10000][30],x[10000][30],c,q[10000];
int aa[10000][30],ss;
int main(void)
{
	scanf("%d",&a);
	for(i=0;i<a;i++){
		q[i]=0;
		for(j=0;j<12;j++) x[i][j]=0;
	}
	for(i=0;i<a;i++){
		f=18;
		g[i]=0;
		scanf("%d",&s[i]);
		while(1){
			scanf("%d",&d[i][g[i]]);
			if(d[i][g[i]]==10) f--;
			g[i]++;
			f--;
			if(f==0) break;
		}
		scanf("%d",&d[i][g[i]]);
		scanf("%d",&d[i][g[i]+1]);
		if(d[i][g[i]]==10||d[i][g[i]+1]==10||d[i][g[i]]+d[i][g[i]+1]==10){
			scanf("%d",&d[i][g[i]+2]);
			g[i]++;
		}
		g[i]+=2;
	}
	for(i=0;i<a;i++){
		j=0;
		c=0;
		while(1){
			if(d[i][j]==10){
				z[i][c]=2;
				x[i][c]=10;
				ss++;
				j++;
				aa[i][c]=j;
				c++;
			}
			else if(d[i][j]+d[i][j+1]==10){
				z[i][c]=1;
				x[i][c]=10;
				j=j+2;
				aa[i][c]=j;
				c++;
			}
			else if(d[i][j]+d[i][j+1]!=10){
				z[i][c]=0;
				x[i][c]=d[i][j]+d[i][j+1];
				j=j+2;
				aa[i][c]=j;
				c++;
			}
			else if(j=g[i]-1&&d[i][j]!=10){
				x[i][c]=d[i][j];
				z[i][c]=0;
				j++;
				aa[i][c]=j;
				c++;
			}
			if(j>=g[i])	break;
		}
	}
	for(i=0;i<a;i++){
		for(j=0;j<12;j++){
			printf("%d ",aa[i][j]);
		}
		printf("\n");
	}
	for(i=0;i<a;i++){
		for(j=0;j<9;j++){
			q[i]+=x[i][j];
			if(z[i][j]==2){
				if(z[i][j+1]==2){
					if(z[i][j+2]==2)
						q[i]=q[i]+x[i][j+1]+x[i][j+2];
					else if(z[i][j+2]!=2)
						q[i]=q[i]+x[i][j+1]+d[i][aa[i][j+1]];
				}
				else if(z[i][j+1]!=2){
					q[i]+=x[i][j+1];
				}
			}
			else if(z[i][j]==1){
				q[i]+=d[i][aa[i][j]];
				printf("1  %d\n",d[i][aa[i][j]]);
			}
		}
		q[i]=q[i]+x[i][9]+x[i][10]+x[i][11];
	}
	for(i=0;i<a;i++){
		for(j=i+1;j<a;j++){
			if(q[i]<q[j]){
				ss=q[i];
				q[i]=q[j];
				q[j]=ss;
				ss=s[i];
				s[i]=s[j];
				s[j]=ss;
			}
		}
	}
	for(i=0;i<a;i++){
		printf("%d %d\n",s[i],q[i]);
	}
	/*for(i=0;i<a;i++){
		for(j=0;j<12;j++){
			printf("|%d %d| ",z[i][j],x[i][j]);
		}
		printf("\n");
	}*/
	return 0;
}