# Will Wang - 12th Grade
# Pittsford Sutherland High School
# American Computer Science League - Intermediate Division
# Contest 3
# PYTHON 3

veitch_ab = [True, True, False, False]
veitch_cd = [False, True, True, False]


def solve(input_string):
    veitch = [[0] * 4] * 4
    str_ans = ""
    for i in range(4):
        B = veitch_ab[i]
        D = veitch_cd[i]
        for j in range(4):
            A = veitch_ab[j]
            C = veitch_cd[j]
            inp_string = input_string
            inp_string = inp_string.replace("A", str(A))
            inp_string = inp_string.replace("B", str(B))
            inp_string = inp_string.replace("C", str(C))
            inp_string = inp_string.replace("D", str(D))
            veitch[i][j] = int(eval(inp_string))
            str_ans += str(int(eval(inp_string)))
    print (hex(int(str_ans, 2))[2:])
    return hex(int(str_ans, 2))[2:]


for inp in range(5):
    try:
        input_array = list(input())
        char = 0
        while char < len(input_array) - 1:
            if input_array[char] != "~" and input_array[char + 1] != "+" and input_array[char] != "+":
                input_array.insert(char + 1, "and")
                char += 1
            char += 1
        input_string = " ".join(input_array)
        input_string = input_string.replace("~", "not")
        input_string = input_string.replace("+", "or")
        ans = solve(input_string)
        if len(ans) < 4:
            while len(ans) < 4:
                ans = "0" + ans
        print(ans)
    except:
        pass