#Intermediate 3
#Skofijska klasicna gimnazija
#Author: Matej Remc
#Program in Python ver 3.8.1
#...............................................................................
vnos, izhod, tabela = open("input.txt", "r"), open("output_Remc.txt", "w"), [[0, 0, 0, 0] for j in range(4)]
for i in vnos:
    negirano, števec = False, 0
    for j in (i.strip(" \n")).split("+"):
        tabela1 = [[0, 0, 0, 0] for j in range(4)]
        for z in j:
            if z == "~":
                negirano = True
                continue
            else:
                if z == "A" and negirano:
                    for k in range(4):
                        tabela1[k][2] += 1
                        tabela1[k][3] += 1
                elif z == "A":
                    for k in range(4):
                        tabela1[k][0] += 1
                        tabela1[k][1] += 1
                elif z == "B" and negirano:
                    for k in range(4):
                        tabela1[2][k] += 1
                        tabela1[3][k] += 1
                elif z == "B":
                    for k in range(4):
                        tabela1[0][k] += 1
                        tabela1[1][k] += 1
                elif z == "C" and negirano:
                    for k in range(4):
                        tabela1[k][0] += 1
                        tabela1[k][3] += 1
                elif z == "C":
                    for k in range(4):
                        tabela1[k][1] += 1
                        tabela1[k][2] += 1
                elif z == "D" and negirano:
                    for k in range(4):
                        tabela1[0][k] += 1
                        tabela1[3][k] += 1
                elif z == "D":
                    for k in range(4):
                        tabela1[1][k] += 1
                        tabela1[2][k] += 1
                števec += 1
            negirano = False
        for k in range(4):
            for l in range(4):
                if tabela1[k][l] == števec and števec != 0:
                    tabela[k][l] = 1
        števec = 0
    for j in range(4):
        izhod.write(str(hex(int(str(tabela[j][0]) + str(tabela[j][1]) + str(tabela[j][2]) + str(tabela[j][3]), 2))[-1]).upper())
    izhod.write("\n")
    tabela = [[0, 0, 0, 0] for j in range(4)]
vnos.close()
izhod.close()