# Takoma Park Middle School
# Int-3
# Contest 3
# River Qiu

f = open("3int_testdata.txt", "r")
nullSet = []
setData = []
variableSet = []
points = []
one = 0
two = 0
three = 0
four = 0
output = ""
count = 0

B = [[0, 0], [0,1], [0,2], [0,3],[1,0], [1,1], [1,2], [1,3]]
notB = [[2, 0], [2,1], [2,2], [2,3],[3,0], [3,1], [3,2], [3,3]]
A = [[0, 0], [1,0], [2,0], [3,0],[0,1], [1,1], [2,1], [3,1]]
notA = [[0, 2], [1,2], [2,2], [3,2],[0,3], [1,3], [2,3], [3,3]]
C = [[0, 1], [1,1], [2,1], [3,1],[0,2], [1,2], [2,2], [3,2]]
notC = [[0, 0], [1,0], [2,0], [3,0],[0,3], [1,3], [2,3], [3,3]]
D = [[1, 0], [1,1], [1,2], [1,3],[2,0], [2,1], [2,2], [2,3]]
notD = [[0, 0], [0,1], [0,2], [0,3],[3,0], [3,1], [3,2], [3,3]]

for x in range(1,6):
       count = 0
       one = 0
       two = 0
       three = 0
       four = 0
       output = ""
       numVariables = 0
       nots = 0
       nullSet = []
       setData = []
       variableSet = []
       points = []

       data = f.readline()
       nullSet = data.split()
       setData = nullSet[0].split("+")

       for value in setData:
              count = 0
              variableSet = []
              if "A" in value:
                     if value[value.find("A") - 1] == "~":
                            variableSet += notA
                            count += 1
                     else:
                            variableSet += A
                            count += 1
              if "B" in value:
                     if value[value.find("B") - 1] == "~":
                            variableSet += notB
                            count += 1
                     else:
                            variableSet += B
                            count += 1
              if "C" in value:
                     if value[value.find("C") - 1] == "~":
                            variableSet += notC
                            count += 1
                     else:
                            variableSet += C
                            count += 1
              if "D" in value:
                     if value[value.find("D") - 1] == "~":
                            variableSet += notD
                            count += 1
                     else:
                            variableSet += D
                            count += 1

              for x in variableSet:
                     if variableSet.count(x) >= count and x not in points:
                            points += [x]

       for y in points:
              if y[0] == 0:
                     if y[1] == 0:
                            one += 8
                     if y[1] == 1:
                            one += 4
                     if y[1] == 2:
                            one += 2
                     if y[1] == 3:
                            one += 1
              if y[0] == 1:
                     if y[1] == 0:
                            two += 8
                     if y[1] == 1:
                            two += 4
                     if y[1] == 2:
                            two += 2
                     if y[1] == 3:
                            two += 1                     
              if y[0] == 2:
                     if y[1] == 0:
                            three += 8
                     if y[1] == 1:
                            three += 4
                     if y[1] == 2:
                            three += 2
                     if y[1] == 3:
                            three += 1
              if y[0] == 3:
                     if y[1] == 0:
                            four += 8
                     if y[1] == 1:
                            four += 4
                     if y[1] == 2:
                            four += 2
                     if y[1] == 3:
                            four += 1
                            
       one = str(hex(one)[2:])
       two = str(hex(two)[2:])
       three = str(hex(three)[2:])
       four = str(hex(four)[2:])
       output = one + two + three + four
       print(output.upper())