# Takoma Park M.S.
# Int-3
# Contest 3
# Sophia Zeng

f = open("3int_testdata.txt", "r")
lines = f.readlines()

for eachLine in lines:
    array = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
    eachLine = eachLine.strip()
    terms = eachLine.split("+")

    for eachTerm in terms:
        reachTerm = list(eachTerm)
        try:
            for x in range(9):
                if reachTerm[x] == "~":
                    del reachTerm[x]
        except:
            reachTerm = "".join(reachTerm)
            if eachTerm == "~BD":
                array[2][0] = 1
                array[2][1] = 1
                array[2][2] = 1
                array[2][3] = 1
                
            if eachTerm == "BD":
                array[1][0] = 1
                array[1][1] = 1
                array[1][2] = 1
                array[1][3] = 1

            if eachTerm == "~B~D":
                array[3][0] = 1
                array[3][1] = 1
                array[3][2] = 1
                array[3][3] = 1

            if eachTerm == "B~D":
                array[0][0] = 1
                array[0][1] = 1
                array[0][2] = 1
                array[0][3] = 1

            if eachTerm == "AC":
                array[0][1] = 1
                array[1][1] = 1
                array[2][1] = 1
                array[3][1] = 1

            if eachTerm == "A~C":
                array[0][0] = 1
                array[1][0] = 1
                array[2][0] = 1
                array[3][0] = 1

            if eachTerm == "~AC":
                array[0][2] = 1
                array[1][2] = 1
                array[2][2] = 1
                array[3][2] = 1

            if eachTerm == "~A~C":
                array[0][3] = 1
                array[1][3] = 1
                array[2][3] = 1
                array[3][3] = 1
                
            if len(reachTerm) == 1:
                if eachTerm == "A" or eachTerm == "B":
                    array[0][0] = 1
                    array[0][1] = 1
                    array[1][0] = 1
                    array[1][1] = 1
                    
                if eachTerm == "~A" or eachTerm == "~B":
                    array[2][2] = 1
                    array[2][3] = 1
                    array[3][2] = 1
                    array[3][3] = 1
                    
                if eachTerm == "B" or eachTerm == "~A":
                    array[0][2] = 1
                    array[1][2] = 1
                    array[0][3] = 1
                    array[1][3] = 1

                if eachTerm == "~B" or eachTerm == "A":
                    array[2][0] = 1
                    array[3][0] = 1
                    array[2][1] = 1
                    array[3][1] = 1

                if eachTerm == "C" or eachTerm == "D":
                    array[1][1] = 1
                    array[1][2] = 1
                    array[2][1] = 1
                    array[2][2] = 1

                if eachTerm == "~C" or eachTerm == "~D":
                    array[0][0] = 1
                    array[0][3] = 1
                    array[3][0] = 1
                    array[3][3] = 1

                if eachTerm == "D" or eachTerm == "~C":
                    array[1][0] = 1
                    array[2][0] = 1
                    array[1][3] = 1
                    array[2][3] = 1

                if eachTerm == "~D" or eachTerm == "C":
                    array[0][1] = 1
                    array[3][1] = 1
                    array[0][2] = 1
                    array[3][2] = 1
                    
            elif len(reachTerm) == 2:
                if "AB" == eachTerm or "A~D" == eachTerm:
                    array[0][0] = 1
                    array[0][1] = 1

                if "A~B" == eachTerm or "AD" == eachTerm:
                    array[2][0] = 1
                    array[2][1] = 1

                if "AD" == eachTerm or "AB" == eachTerm:
                    array[1][0] = 1
                    array[1][1] = 1

                if "A~D" == eachTerm or "A~B" == eachTerm:
                    array[3][0] = 1
                    array[3][1] = 1

                if "~AB" == eachTerm or "~A~D" == eachTerm:
                    array[0][2] = 1
                    array[0][3] = 1

                if "BC" == eachTerm or "C~D" == eachTerm:
                    array[0][1] = 1
                    array[0][2] = 1

                if "B~C" == eachTerm or "~C~D" == eachTerm:
                    array[0][0] = 1
                    array[0][3] = 1

                if "~BC" == eachTerm or "CD" == eachTerm:
                    array[2][1] = 1
                    array[2][2] = 1

                if "CD" == eachTerm or "BC" == eachTerm:
                    array[1][1] = 1
                    array[1][2] = 1

                if "C~D" == eachTerm or "~BC" == eachTerm:
                    array[3][1] = 1
                    array[3][2] = 1
                    
                if "~AD" == eachTerm or "~AB" == eachTerm:
                    array[1][2] = 1
                    array[1][3] = 1

                if "~CD" == eachTerm or "B~C" == eachTerm:
                    array[1][0] = 1
                    array[1][3] = 1

                if "~A~B" == eachTerm or "~AD" == eachTerm:
                    array[2][2] = 1
                    array[2][3] = 1
                    
                if "~A~D" == eachTerm or "~A~B" == eachTerm:
                    array[3][2] = 1
                    array[3][3] = 1

                if "~B~C" == eachTerm or "~CD" == eachTerm:
                    array[2][0] = 1
                    array[2][3] = 1

                if "~C~D" == eachTerm or "~B~C" == eachTerm:
                    array[3][0] = 1
                    array[3][3] = 1

            elif len(reachTerm) == 3:
                if ("A" in eachTerm and "~C" in eachTerm) or ("A" in eachTerm and "C" in eachTerm) or ("~A" in eachTerm and "C" in eachTerm) or ("~A" in eachTerm and "~C" in eachTerm):
                    if "~A" in eachTerm and "~C" in eachTerm:
                        col = 3
                        
                    elif "A" in eachTerm and "~C" in eachTerm:
                        col = 0

                    elif "~A" in eachTerm and "C" in eachTerm:
                        col = 2
                    
                    elif "A" in eachTerm and "C" in eachTerm:
                        col = 1

                    if "~B" in eachTerm:
                        row1 = 2
                        row2 = 3
                        
                    elif "B" in eachTerm:
                        row1 = 0
                        row2 = 1

                    if "~D" in eachTerm:
                        row1 = 0
                        row2 = 3

                    elif "D" in eachTerm:
                        row1 = 1
                        row2 = 2

                    array[row1][col] = 1
                    array[row2][col] = 1

                else:
                    if "~B" in eachTerm and "~D" in eachTerm:
                        row = 3
                        
                    elif "B" in eachTerm and "~D" in eachTerm:
                        row = 0

                    elif "~B" in eachTerm and "D" in eachTerm:
                        row = 2
                        
                    elif "B" in eachTerm and "D" in eachTerm:
                        row = 1

                    if "~A" in eachTerm:
                        col1 = 2
                        col2 = 3
                        
                    elif "A" in eachTerm:
                        col1 = 0
                        col2 = 1

                    if "~C" in eachTerm:
                        col1 = 0
                        col2 = 3

                    elif "C" in eachTerm:
                        col1 = 1
                        col2 = 2
                        
                    array[row][col1] = 1
                    array[row][col2] = 1
                
            elif len(reachTerm) == 4:
                if "~A" in eachTerm and "~C" in eachTerm:
                    col = 3
                    
                elif "A" in eachTerm and "~C" in eachTerm:
                    col = 0

                elif "~A" in eachTerm and "C" in eachTerm:
                    col = 2
                        
                elif "A" in eachTerm and "C" in eachTerm:
                    col = 1

                if "~B" in eachTerm and "~D" in eachTerm:
                    row = 3

                elif "B" in eachTerm and "~D" in eachTerm:
                    row = 0

                elif "~B" in eachTerm and "D" in eachTerm:
                    row = 2
                        
                elif "B" in eachTerm and "D" in eachTerm:
                    row = 1
                        
                array[row][col] = 1

    part1 = ""
    part2 = ""
    part3 = ""
    part4 = ""

    for a in list(array[0]):
        part1 += str(a)

    for b in list(array[1]):
        part2 += str(b)

    for c in list(array[2]):
        part3 += str(c)
        
    for d in list(array[3]):
        part4 += str(d)

    part1 = str(hex(int(part1, 2))).upper().strip("0X")
    part2 = str(hex(int(part2, 2))).upper().strip("0X")
    part3 = str(hex(int(part3, 2))).upper().strip("0X")
    part4 = str(hex(int(part4, 2))).upper().strip("0X")

    if part1 == "":
        part1 = "0"

    if part2 == "":
        part2 = "0"

    if part3 == "":
        part3 = "0"

    if part4 == "":
        part4 = "0"
        
    allParts = part1 + part2 + part3 + part4
    print(allParts)
    
f.close()