"""
Sameer Pai
Senior Division
Bergen County Academies
"""

def isPrime(x):
	for i in range(2, x):
		if(x % i == 0):
			return False
	return True

def isSquare(x):
	for i in range(2, x):
		if(i * i == x):
			return True
	return False



def doRoll(roll, pla, opp):
	badints = [[6, 8], [11, 13], [16, 18], [21, 23], [26, 28], [34, 36], [39, 41], [44, 46], [49, 51]]
	if(len(pla) == 0):
		return
	tar = pla[0] + roll
	if tar > 52 or tar in pla or tar in opp:
		return
	if isPrime(tar):
		for i in range(6):
			if (tar+1) in (pla[1:]+opp):
				break
			tar = tar + 1
	elif isSquare(tar):
		for i in range(6):
			if (tar-1) in (pla[1:]+opp):
				break
			tar = tar - 1
	else:
		for l in badints:
			if pla[0] <= l[0] and tar >= l[1]:
				while tar > pla[0]:
					if tar % roll == 0 and tar not in (pla[1:] + opp):
						break
					tar = tar - 1
	pla[0] = tar
	if pla[0] == 52:
		pla = pla[1:]
	pla.sort()


def solve(s):
	inp = list(map(int, s.split()))
	opp = inp[0:3]
	pla = inp[3:6]
	pla.sort()
	opp.sort()
	r = inp[6]
	inp = inp[7:]
	curp = False
	for roll in inp:
		if(curp):
			doRoll(roll, pla, opp)
		else:
			doRoll(roll, opp, pla)
		curp = not curp
	return(str(sum(opp)) + " " + str(sum(pla)))


f = open("4sr_sampledata.txt", "r")
i = 1
while True:
	s = f.readline().strip()
	if not s:
		break
	print(str(i) + ".", solve(s))
	i += 1