#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<map>
int F(int*a)
{
	int s,f,c,r;
	for(s=f=c=r=0;c<9;)
	{
		r+=*a;
		if(*a+s==10)
		{
			if(f)r+=a[1];
			else r+=a[1]+a[2];
			f=0,s=0;
			++c;
		}
		else
		{
			if(f)f=0,++c,s=0;
			else f=1,s=*a;
		}
		++a;
	}
	s=*a+a[1];
	if(s>9)s+=a[2];
	return r+s;
}
int main()
{
	int m,i,j,x[32],l;
	char*p,s[256];
	std::pair<int,int>a[40];
	while(scanf("%d",&m),m)
	{
		for(i=0;i<m;++i)
		{
			scanf("%d",&a[i].second);
			fgets(s,256,stdin);
			for(l=0,p=strtok(s," ");p;p=strtok(0," "))
				x[l++]=atoi(p);
			a[i].first=-F(x);
		}
		std::sort(a,a+m);
		for(i=0;i<m;++i)printf("%d %d\n",a[i].second,-a[i].first);
	}
	return 0;
}