# Devon Lai
# Bergen County Academies
# Junior Division

file = open("3jr_sampledata.txt", "r")

for line in file:
    line = line.strip()
    line = line.lower()
    total = 0
    if line[1] in ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']:
        total += int(line[1])
    else:
        if line[1] == "a":
            total += 10
        elif line[1] == "b":
            total += 11
        elif line[1] == "c":
            total += 12
        elif line[1] == "d":
            total += 13
        elif line[1] == "e":
            total += 14
        elif line[1] == "f":
            total += 15
    if line[0] in ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']:
        total += int(line[0]) * 16
    else:
        if line[0] == "a":
            total += 10 * 16
        elif line[0] == "b":
            total += 11 * 16
        elif line[0] == "c":
            total += 12 * 16
        elif line[0] == "d":
            total += 13 * 16
        elif line[0] == "e":
            total += 14 * 16
        elif line[0] == "f":
            total += 15 * 16
    decimal = int(total)

    binaryList = []
    if (decimal >= 128):
        binaryList.append("1")
        decimal -= 128
    else:
        binaryList.append("0")
    if (decimal >= 64):
        binaryList.append("1")
        decimal -= 64
    else:
        binaryList.append("0")
    if (decimal >= 32):
        binaryList.append("1")
        decimal -= 32
    else:
        binaryList.append("0")
    if (decimal >= 16):
        binaryList.append("1")
        decimal -= 16
    else:
        binaryList.append("0")
    if (decimal >= 8):
        binaryList.append("1")
        decimal -= 8
    else:
        binaryList.append("0")
    if (decimal >= 4):
        binaryList.append("1")
        decimal -= 4
    else:
        binaryList.append("0")
    if (decimal >= 2):
        binaryList.append("1")
        decimal -= 2
    else:
        binaryList.append("0")
    if (decimal >= 1):
        binaryList.append("1")
        decimal -= 1
    else:
        binaryList.append("0")
    binaryNum = ""
    for x in binaryList:
        binaryNum += x

    boolValue = ""
    if binaryList[0] == '1':
        if binaryList[1] == '1' and binaryList[2] == '1' and binaryList[3] == '1':
            boolValue += "B+"
            binaryList[0] = 0
            binaryList[1] = 0
            binaryList[2] = 0
            binaryList[3] = 0
    if binaryList[4] == '1':
        if binaryList[5] == '1' and binaryList[6] == '1' and binaryList[7] == '1':
            boolValue += "~B+"
            binaryList[4] = 0
            binaryList[5] = 0
            binaryList[6] = 0
            binaryList[7] = 0
    if binaryList[0] == '1':
        if binaryList[4] == '1' and binaryList[1] == '1' and binaryList[5] == '1':
            boolValue += "A+"
            binaryList[0] = 0
            binaryList[4] = 0
            binaryList[2] = 0
            binaryList[5] = 0
    if binaryList[1] == '1':
        if binaryList[2] == '1' and binaryList[5] == '1' and binaryList[6] == '1':
            boolValue += "C+"
            binaryList[1] = 0
            binaryList[2] = 0
            binaryList[5] = 0
            binaryList[6] = 0
    if binaryList[2] == '1':
        if binaryList[3] == '1' and binaryList[6] == '1' and binaryList[7] == '1':
            boolValue += "~A+"
            binaryList[2] = 0
            binaryList[3] = 0
            binaryList[6] = 0
            binaryList[7] = 0
    if binaryList[0] == '1':
        if binaryList[4] == '1' and binaryList[3] == '1' and binaryList[7] == '1':
            boolValue += "~C+"
            binaryList[0] = 0
            binaryList[4] = 0
            binaryList[3] = 0
            binaryList[7] = 0
    if binaryList[0] == '1':
        if binaryList[1] == '1':
            boolValue += "AB+"
            binaryList[0] = 0
            binaryList[1] = 0
    if binaryList[1] == '1':
        if binaryList[2] == '1':
            boolValue += "BC+"
            binaryList[1] = 0
            binaryList[2] = 0
    if binaryList[2] == '1':
        if binaryList[3] == '1':
            boolValue += "~AB+"
            binaryList[2] = 0
            binaryList[3] = 0
    if binaryList[4] == '1':
        if binaryList[5] == '1':
            boolValue += "A~B+"
            binaryList[4] = 0
            binaryList[5] = 0
    if binaryList[5] == '1':
        if binaryList[6] == '1':
            boolValue += "~BC+"
            binaryList[5] = 0
            binaryList[6] = 0
    if binaryList[6] == '1':
        if binaryList[7] == '1':
            boolValue += "~A~B+"
            binaryList[6] = 0
            binaryList[7] = 0
    if binaryList[0] == '1':
        if binaryList[4] == '1':
            boolValue += "A~C+"
            binaryList[0] = 0
            binaryList[4] = 0
    if binaryList[1] == '1':
        if binaryList[5] == '1':
            boolValue += "AC+"
            binaryList[1] = 0
            binaryList[5] = 0
    if binaryList[2] == '1':
        if binaryList[6] == '1':
            boolValue += "~AC+"
            binaryList[2] = 0
            binaryList[6] = 0
    if binaryList[3] == '1':
        if binaryList[7] == '1':
            boolValue += "~A~C+"
            binaryList[3] = 0
            binaryList[7] = 0
    if binaryList[0] == '1':
        if binaryList[3] == '1':
            boolValue += "B~C+"
            binaryList[0] = 0
            binaryList[3] = 0
    if binaryList[4] == '1':
        if binaryList[7] == '1':
            boolValue += "~B~C+"
            binaryList[4] = 0
            binaryList[7] = 0
    if binaryList[0] == '1':
        boolValue += "AB~C+"
        binaryList[0] = 0
    if binaryList[1] == '1':
        boolValue += "ABC+"
        binaryList[1] = 0
    if binaryList[2] == '1':
        boolValue += "~ABC+"
        binaryList[2] = 0
    if binaryList[3] == '1':
        boolValue += "~AB~C+"
        binaryList[3] = 0
    if binaryList[4] == '1':
        boolValue += "A~B~C+"
        binaryList[4] = 0
    if binaryList[5] == '1':
        boolValue += "A~BC+"
        binaryList[5] = 0
    if binaryList[6] == '1':
        boolValue += "~A~BC+"
        binaryList[6] = 0
    if binaryList[7] == '1':
        boolValue += "~A~B~C+"
        binaryList[7] = "1"

    boolList = []
    for x in boolValue:
        boolList.append(x)
    length = len(boolValue)
    del boolList[length - 1]
    boolString = ""
    for x in boolList:
        boolString += x
    print(boolString)