#Ananya Seelam
#3/12/20
#Int5
#Enloe
#contest 3
def matrixMaker(boolVal):
    n=4
    matrix = [[0] * n for i in range(n)]
    #matrix[row][col]
    if(boolVal.find('A')==0):
        for i in range(4):
            matrix[i][0]=1
            matrix[i][1]=1
        boolVal=boolVal[1:]
    elif(boolVal.find("~A")==0):
        for i in range(4):
            matrix[i][2]=1
            matrix[i][3]=1
        boolVal=boolVal[2:]
    elif(boolVal.find('B')==0):
        for i in range(4):
            matrix[0][i]=1
            matrix[1][i]=1
        boolVal=boolVal[1:]
    elif(boolVal.find('~B')==0):
        for i in range(4):
            matrix[2][i]=1
            matrix[3][i]=1
        boolVal=boolVal[2:]
    elif(boolVal.find('C')==0):
        for i in range(4):
            matrix[i][1]=1
            matrix[i][2]=1
        boolVal=boolVal[1:]
    elif(boolVal.find('~C')==0):
        for i in range(4):
            matrix[i][0]=1
            matrix[i][3]=1
        boolVal=boolVal[2:]
    elif(boolVal.find('D')==0):
        for i in range(4):
            matrix[1][i]=1
            matrix[2][i]=1
        boolVal=boolVal[1:]
    elif(boolVal.find('~D')==0):
        for i in range(4):
            matrix[0][i]=1
            matrix[3][i]=1
        boolVal=boolVal[2:]
    

    while(len(boolVal)>0):
        #print('here')
        if(boolVal.find('B')==0):
            for i in range(4):
                matrix[2][i]=0
                matrix[3][i]=0
            if(len(boolVal)==1):
                boolVal=''
            else:
                boolVal=boolVal[1:]
##            print(boolVal)
        elif(boolVal.find('~B')==0):
            for i in range(4):
                matrix[0][i]=0
                matrix[1][i]=0
            if(len(boolVal)==1):
                boolVal=''
            else:
                boolVal=boolVal[2:]
        elif(boolVal.find('C')==0):
            for i in range(4):
                matrix[i][0]=0
                matrix[i][3]=0
            if(len(boolVal)==1):
                boolVal=''
            else:
                boolVal=boolVal[1:]
        elif(boolVal.find('~C')==0):
            for i in range(4):
                matrix[i][1]=0
                matrix[i][2]=0
            if(len(boolVal)==1):
                boolVal=''
            else:
                boolVal=boolVal[2:]
        elif(boolVal.find('D')==0):
            for i in range(4):
                matrix[0][i]=0
                matrix[3][i]=0
            if(len(boolVal)==1):
                boolVal=''
            else:
                boolVal=boolVal[1:]
        elif(boolVal.find('~D')==0):
            for i in range(4):
                matrix[1][i]=0
                matrix[2][i]=0
            if(len(boolVal)==1):
                boolVal=''
            else:
                boolVal=boolVal[2:]
        #print(boolVal)
##    for row in matrix:
##        print(' '.join([str(elem) for elem in row]))
    return (matrix)


filename = 'F:\\3int.txt'

with open(filename) as file_object:
    lines = file_object.readlines()

for line in lines:
    input1=line.rstrip()  
    vals = []
    counter = 0
    while len(input1)>0:
        plusPos=input1.find('+')
        if(plusPos == -1):
            vals.append(input1)
            input1=''
        else:
            vals.append(input1[0:plusPos])
            input1 = input1[plusPos+1:]
    #print(vals)
    matrices = []
    for val in vals:
        matrices.append(matrixMaker(val))
        #print("matrix done")
    #print(matrices)
    finalMatrix = [[0] * 4 for i in range(4)]
    for matrix in matrices:
        for i in range(4):
            for j in range(4):
                finalMatrix[i][j] = finalMatrix[i][j] + matrix[i][j]
                if(finalMatrix[i][j]>0):
                    finalMatrix[i][j]=1
##    for row in finalMatrix:
##        print(' '.join([str(elem) for elem in row]))
    hexList = []
    for row in finalMatrix:
        binNum=''
        for val in row:
            binNum = binNum+str(val)
        hexList.append(binNum)
    output = ''
    for hexVal in hexList:
        if (hexVal == '0000'):
            output = output + '0'
        if (hexVal == '0001'):
            output = output + '1'
        if (hexVal == '0010'):
            output = output + '2'
        if (hexVal == '0011'):
            output = output + '3'
        if (hexVal == '0100'):
            output = output + '4'
        if (hexVal == '0101'):
            output = output + '5'
        if (hexVal == '0110'):
            output = output + '6'
        if (hexVal == '0111'):
            output = output + '7'
        if (hexVal == '1000'):
            output = output + '8'
        if (hexVal == '1001'):
            output = output + '9'
        if (hexVal == '1010'):
            output = output + 'A'
        if (hexVal == '1011'):
            output = output + 'B'
        if (hexVal == '1100'):
            output = output + 'C'
        if (hexVal == '1101'):
            output = output + 'D'
        if (hexVal == '1110'):
            output = output + 'E'
        if (hexVal == '1111'):
            output = output + 'F'
    print(output)