# Name: Angelika Wang
# Team: We Sense
# Intermediate Division
# ACSL Contest #3
# Date of Program: 3/8/2020
# Grade: 8th
# Language: Python
# Input Data Method: interactively key in

def findVal(var,vals):
    a = vals[0]
    b = vals[1]
    c = vals[2]
    d = vals[3]
    if var == 'A':
        return a
    elif var == 'B':
        return b
    elif var == 'C':
        return c
    elif var == 'D':
        return d
for times in range(0,5):
    expression = input()
    expression = expression.split('+')
    diagram = [[[True,True,False,False],[True,True,True,False],[False,True,True,False],[False,True,False,False]],[[True,True,False,True],[True,True,True,True],[False,True,True,True],[False,True,False,True]],[[True,False,False,True],[True,False,True,True],[False,False,True,True],[False,False,False,True]],[[True,False,False,False],[True,False,True,False],[False,False,True,False],[False,False,False,False]]]
    result = [[],[],[],[]]

#Boolean Expression evaluation
    for row in range(0,4):
        for square in range(0,4):
            ORresult = False
            for term in range(0,len(expression)):
                ANDresult = True
                i = 0
                while i < len(expression[term]):
                    if expression[term][i] != '~':
                        Varval = findVal(expression[term][i],diagram[row][square])
                        ANDresult = ANDresult and Varval
                        i = i+1
                    else:
                        Varval = findVal(expression[term][i+1],diagram[row][square])
                        ANDresult = ANDresult and not Varval
                        i = i+2
                ORresult = ORresult or ANDresult
            if ORresult == False:
                result[row].append(0)
            else:
                result[row].append(1)

#covert diagram to hexadecimal
    output = ''
    for x in range(0,len(result)):
        binary = ''.join([str(item)for item in result[x]])
        hexdec = str(hex(int(binary,2)))
        output += list(hexdec)[2].upper()
    print(output)