# Takoma Park M.S.
# Jr-5
# Contest 3
# Daniel He
def yes(x):
	arrayOne = []
	arrayTwo = []
	for digit in x:
		aList = []
		if arrayOne == []:
			if digit == "A":
				arrayOne = ['1','0','1','0']
			elif digit == "B":
				arrayOne = ['1','0','1','1']
			elif digit == "C":
				arrayOne = ['1','1','0','0']
			elif digit == "D":
				arrayOne = ['1','1','0','1']
			elif digit == "E":
				arrayOne = ['1','1','1','0']
			elif digit == "F":
				arrayOne = ['1','1','1','1']
			else:
				digit = int(digit)
				a = bin(digit)
				for value in a:
					aList += value
				aList = aList[2:]
				while len(aList) != 4:
					aList.insert(0,'0')
				for value in aList:
					arrayOne.append(value)
		else:
			if digit == "A":
				arrayTwo = ['1','0','1','0']
			elif digit == "B":
				arrayTwo = ['1','0','1','1']
			elif digit == "C":
				arrayTwo = ['1','1','0','0']
			elif digit == "D":
				arrayTwo = ['1','1','0','1']
			elif digit == "E":
				arrayTwo = ['1','1','1','0']
			elif digit == "F":
				arrayTwo = ['1','1','1','1']
			else:
				digit = int(digit)
				a = bin(digit)
				for value in a:
					aList += value
				aList = aList[2:]
				while len(aList) != 4:
					aList.insert(0,'0')
				for value in aList:
					arrayTwo.append(value)
	expression = ""
	if arrayOne == ['1','1','1','1']:
		expression += "+ B "
		arrayOne = ['0','0','0','0']
	if arrayTwo == ['1','1','1','1']:
		expression += "+ ~B "
		arrayTwo = ['0','0','0','0']
	for x in range(5):
		if arrayOne[x-2:x] == ['1','1'] and arrayTwo[x-2:x] == ['1','1']:
			arrayOne[x-2:x] = ['0','0']
			arrayTwo[x-2:x] = ['0','0']
			if x == 2:
				expression += "+ A "
			elif x == 3:
				expression += "+ C "
			elif x == 4:
				expression += "+ ~A "
	if arrayOne[0] == "1" and arrayOne[3] == "1" and arrayTwo[0] == "1" and arrayTwo[3] == "1":
		arrayOne[0] = "0"
		arrayOne[3] = "0"
		arrayTwo[0] = "0"
		arrayTwo[3] = "0"
		expression += "+ ~C "
	for x in range(5):
		if arrayOne[x-2:x] == ['1','1']:
			arrayOne[x-2:x] = ['0','0']
			if x == 2:
				expression += "+ AB "
			elif x == 3:
				expression += "+ BC "
			elif x == 4:
				expression += "+ ~AB "
	for x in range(5):
		if arrayTwo[x-2:x] == ['1','1']:
			arrayTwo[x-2:x] = ['0','0']
			if x == 2:
				expression += "+ A~B "
			elif x == 3:
				expression += "+ ~BC "
			elif x == 4:
				expression += "+ ~A~B "
	for x in range(5):
		if arrayOne[x-1:x] == ['1'] and arrayTwo[x-1:x] == ['1']:
			arrayOne[x-1:x] = ['0']
			arrayTwo[x-1:x] = ['0']
			if x == 1:
				expression += "+ A~C "
			elif x == 2:
				expression += "+ AC "
			elif x == 3:
				expression += "+ ~AC "
			elif x == 4:
				expression += "+ ~A~C "
	if arrayOne[0] == "1" and arrayOne[3] == "1":
		arrayOne[0] = "0"
		arrayOne[3] = "0"
		expression += "+ B~C "
	if arrayTwo[0] == "1" and arrayTwo[3] == "1":
		arrayTwo[0] = "0"
		arrayTwo[3] = "0"
		expression += "+ ~B~C "
	for digit in range(4):
		if arrayOne[digit] == "1":
			if digit == 0:
				expression += "+ AB~C "
			elif digit == 1:
				expression += "+ ABC "
			elif digit == 2:
				expression += "+ ~ABC "
			elif digit == 3:
				expression += "+ ~AB~C "
	for digit in range(4):
		if arrayTwo[digit] == "1":
			if digit == 0:
				expression += "+ A~B~C "
			elif digit == 1:
				expression += "+ A~BC "
			elif digit == 2:
				expression += "+ ~A~BC "
			elif digit == 3:
				expression += "+ ~A~B~C "
	return(expression[1:])
arpha = open("3jr_testdata.txt", "r")
number = 0
for rine in arpha.readlines():
	x = yes(rine[0:2])
	number += 1
	print(str(number)+"." + x)
arpha.close()