# Name: Zhijia Ye
# Team: We Sense
# Intermediate Division
# ACSL Contest #3
# Date of Program: 3/8/2020
# Grade: 9
# Language: Python
# Input Data Method: Text file (.txt)
INPUT_FILE_NAME = "input.txt"

grid = [[["A", "B", "~C", "~D"], ["A", "B", "C", "~D"],
            ["~A", "B", "C", "~D"], ["~A", "B", "~C", "~D"]],
        [["A", "B", "~C", "D"], ["A", "B", "C", "D"],
            ["~A", "B", "C", "D"], ["~A", "B", "~C", "D"]],
        [["A", "~B", "~C", "D"], ["A", "~B", "C", "D"],
            ["~A", "~B", "C", "D"], ["~A", "~B", "~C", "D"]],
        [["A", "~B", "~C", "~D"], ["A", "~B", "C", "~D"],
            ["~A", "~B", "C", "~D"], ["~A", "~B", "~C", "~D"]]]

hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 'A', 'B', 'C', 'D', 'E', 'F']

with open(INPUT_FILE_NAME, "r") as fin:
    for data in fin.readlines():
        terms = data.strip().split("+")
        split_terms = []
        for t in terms:
            terms_in_t = []
            i = 0
            while i < len(t):
                if t[i] == "~":
                    terms_in_t.append(t[i:i+2])
                    i += 2
                else:
                    terms_in_t.append(t[i])
                    i += 1
            split_terms.append(terms_in_t)
        veitch = [[0, 0, 0, 0],
                    [0, 0, 0, 0],
                    [0, 0, 0, 0],
                    [0, 0, 0, 0]]
        for t in split_terms:
            for x in range(0, 4):
                for y in range(0, 4):
                    flag = 0
                    for i in t:
                        if i not in grid[x][y]:
                            flag = 1
                            break
                    if flag == 0:
                        veitch[x][y] = 1
        answer = ""
        for x in veitch:
            num = x[0]*8 + x[1]*4 + x[2]*2 + x[3]*1
            answer += hex[num]
        print(answer)