#Esther Zhu
#Mar. 12, 2020
#Int5
#Enloe
#Potter


inputs=[]
filename = 'F:\\3int.txt'
with open(filename) as file_object:
    for line in file_object:
        inputs.append(line)
for x in range(len(inputs)-1):
    inputs[x]=inputs[x][:len(inputs[x])-1]
    
for line in inputs:
    lock=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
    line=line+'+'
    while(not line==""):
        el=line[0:line.find('+')]
        line=line[line.find('+')+1:]
        #mark first elem
        ma=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
        if el[0:2]=="~A":
            for i in range(0,4):
                ma[i][2]=1
                ma[i][3]=1
            el=el[2:]
        elif el[0:2]=="~B":
            for i in range(0,4):
                ma[2][i]=1
                ma[3][i]=1
            el=el[2:]
        elif el[0:2]=="~C":
            for i in range(0,4):
                ma[i][0]=1
                ma[i][3]=1
            el=el[2:]
        elif el[0:2]=="~D":
            for i in range(0,4):
                ma[0][i]=1
                ma[3][i]=1
            el=el[2:]
        elif el[0:1]=="A":
            for i in range(0,4):
                ma[i][0]=1
                ma[i][1]=1
            el=el[1:]
        elif el[0:1]=="B":
            for i in range(0,4):
                ma[0][i]=1
                ma[1][i]=1
            el=el[1:]
        elif el[0:1]=="C":
            for i in range(0,4):
                ma[i][1]=1
                ma[i][2]=1
            el=el[1:]
        elif el[0:1]=="D":
            for i in range(0,4):
                ma[1][i]=1
                ma[2][i]=1
            el=el[1:]
        while(not el==""):#erase
            if el[0:2]=="~A":
                for i in range(0,4):
                    ma[i][0]=0
                    ma[i][1]=0
                el=el[2:]
            elif el[0:2]=="~B":
                for i in range(0,4):
                    ma[0][i]=0
                    ma[1][i]=0
                el=el[2:]
            elif el[0:2]=="~C":
                for i in range(0,4):
                    ma[i][1]=0
                    ma[i][2]=0
                el=el[2:]
            elif el[0:2]=="~D":
                for i in range(0,4):
                    ma[1][i]=0
                    ma[2][i]=0
                el=el[2:]
            elif el[0:1]=="A":
                for i in range(0,4):
                    ma[i][2]=0
                    ma[i][3]=0
                el=el[1:]
            elif el[0:1]=="B":
                for i in range(0,4):
                    ma[2][i]=0
                    ma[3][i]=0
                el=el[1:]
            elif el[0:1]=="C":
                for i in range(0,4):
                    ma[i][0]=0
                    ma[i][3]=0
                el=el[1:]
            elif el[0:1]=="D":
                for i in range(0,4):
                    ma[0][i]=0
                    ma[3][i]=0
                el=el[1:]
            #add into lock
        for i in range(0,4):
            for j in range(0,4):
                if ma[i][j]==1:
                    lock[i][j]=1
    hexa=""
    for i in range(0,4):
        x=(lock[i][0]*8)+(lock[i][1]*4)+(lock[i][2]*2)+(lock[i][3])
        st=hex(x)
        hexa=hexa+st[2:]
    print(hexa.upper())