#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[41],d[41][22],f[41],g,h[41],i,j,z,x;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			scanf("%d",&s[i]);
			f[i]=0;
			g=1;
			h[i]=0;
			while(1){
				scanf("%d",&d[i][f[i]]);
				h[i]+=d[i][f[i]];
				if(d[i][f[i]]==10&&g%2==1){
					//printf("aaaaaaa\n");
					g++;
				}
				g++;
				f[i]++;
				if(g==19) break;
			}
			scanf("%d %d",&d[i][f[i]],&d[i][f[i]+1]);
			h[i]+=d[i][f[i]]+d[i][f[i]+1];
			if(d[i][f[i]]+d[i][f[i]+1]>=10){
				scanf("%d",&d[i][f[i]+2]);
				h[i]+=d[i][f[i]+2];
			}
			z=0;
			for(j=0;j<f[i];j++){
				if(d[i][j]==10&&z==0){
					h[i]+=d[i][j+1]+d[i][j+2];
				}
				else if(z==0) z=1;
				else if(d[i][j-1]+d[i][j]==10&&z==1){
					h[i]+=d[i][j+1];
					z=0;
				}
				else z=0;
			}
		}
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(h[i]<h[j]){
					x=h[i];
					h[i]=h[j];
					h[j]=x;
					x=s[i];
					s[i]=s[j];
					s[j]=x;
				}
			}
		}
		for(i=0;i<a;i++) printf("%d %d\n",s[i],h[i]);
	}
	return 0;
}