# -----------------------------------------------------------------------------------------
# Oak Valley Coding Club 2019-2020
# Solution for 2020 ACSL Programming Problem #3 – Junior Division
# Author :  Vinay Rajagopalan
# Language: Python 3.x
# -----------------------------------------------------------------------------------------


import ovcc_grader_strings

# answers = []    # never define variables as global, always use locally inside the functions, send as input argument if needed
# twoDArray = []  # never define variables as global, always use locally inside the functions, send as input argument if needed
one = 1  # this is constant that never changes, so its okay to define globally

def FindGroupsOfFour(twoDArray,answers):
    rows = len(twoDArray)
    cols = len(twoDArray[0])
    for r in range(0, rows):
        for c in range(0, cols):
            if twoDArray[r][c] == one:
                if c==0:
                    if twoDArray[r][c] == twoDArray[r][c + 1] & twoDArray[r][c] == twoDArray[r][c + 2] & twoDArray[r][c] == twoDArray[r][c + 3]:
                        if r==0:
                            answers.append("B")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                            twoDArray[r][c+2] = 0
                            twoDArray[r][c+3] = 0
                        elif r == 1:
                            answers.append("~B")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                            twoDArray[r][c+2] = 0
                            twoDArray[r][c+3] = 0
                if (c<=2) & (r<1):
                    if twoDArray[r][c+1] == 1 & twoDArray[r-1][c] == 1 & twoDArray[r-1][c+1] == 1:
                        if c == 0:
                            answers.append("A")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                            twoDArray[r-1][c] = 0
                            twoDArray[r-1][c+1] = 0
                        elif c == 1:
                            answers.append("C")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                            twoDArray[r-1][c] = 0
                            twoDArray[r-1][c+1] = 0
                        elif c == 2:
                            answers.append("~A")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                            twoDArray[r-1][c] = 0
                            twoDArray[r-1][c+1] = 0
    return answers

def FindGroupsOfFourWithWrapAround(twoDArray,answers):
    rows = len(twoDArray)
    cols = len(twoDArray[0])
    for r in range(0, rows):
        for c in range(0, cols):
            if twoDArray[r][c] == one:
                if(c==0) & (r==0):
                    if twoDArray[r][c+3]==1 & twoDArray[r-1][c]==1 & twoDArray[r-1][c+3]==1:
                        answers.append("~C")
                        twoDArray[r][c+3] = 0
                        twoDArray[r-1][c] = 0
                        twoDArray[r-1][c+3] = 0
                        twoDArray[r][c] = 0
    return answers

def FindGroupsOfTwo(twoDArray,answers):
    rows = len(twoDArray)
    cols = len(twoDArray[0])
    for r in range(0, rows):
        for c in range(0, cols):
            if twoDArray[r][c] == 1:
                if c<=2:
                    if (twoDArray[r][c+1]) == 1:
                        if (c==0) & (r==0):
                            answers.append("AB")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                        elif (c==1) & (r==0):
                            answers.append("BC")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                        elif (c==2) & (r==0):
                            answers.append("~AB")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                        elif (c==0) & (r==1):
                            answers.append("A~B")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                        elif (c==1) & (r==1):
                            answers.append("~BC")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                        elif (c==2) & (r==1):
                            answers.append("~A~B")
                            twoDArray[r][c] = 0
                            twoDArray[r][c+1] = 0
                if r == 0:
                    if twoDArray[r-1][c] == 1:
                        if c==0:
                            answers.append("A~C")
                            twoDArray[r][c] = 0
                            twoDArray[r-1][c] = 0
                        elif c==1:
                            answers.append("AC")
                            twoDArray[r][c] = 0
                            twoDArray[r-1][c] = 0
                        elif c==2:
                            answers.append("~AC")
                            twoDArray[r][c] = 0
                            twoDArray[r-1][c] = 0
                        elif c==3:
                            answers.append("~A~C")
                            twoDArray[r][c] = 0
                            twoDArray[r-1][c] = 0
    return answers

def FindGroupsOfTwoWithWrap(twoDArray,answers):
    rows = len(twoDArray)
    cols = len(twoDArray[0])
    for r in range(0, rows):
        for c in range(0, cols):
            if twoDArray[r][c] == one:
                if (c == 0):
                    if (twoDArray[r][c + 3] == 1) & (r==0):
                        answers.append("B~C")
                        twoDArray[r][c] = 0
                        twoDArray[r][c+3]=0
                    if twoDArray[r][c+3] == 1 & r==1:
                        answers.append("~B~C")
                        twoDArray[r][c] = 0
                        twoDArray[r][c+3]=0
    return answers

def Singles(twoDArray,answers):
    rows = len(twoDArray)
    cols = len(twoDArray[0])
    for r in range(0, rows):
        for c in range(0, cols):
            if twoDArray[r][c]==1:
                if (r==0) & (c==0):
                    answers.append("AB~C")
                    twoDArray[r][c]=0
                if (r==0) & (c==1):
                    answers.append("ABC")
                    twoDArray[r][c] = 0
                if (r==0) & (c==2):
                    answers.append("~ABC")
                    twoDArray[r][c] = 0
                if (r==0) & (c==3):
                    answers.append("~AB~C")
                    twoDArray[r][c] = 0
                if (r==1) & (c==0):
                    answers.append("A~B~C")
                    twoDArray[r][c] = 0
                if (r==1) & (c==1):
                    answers.append("A~BC")
                    twoDArray[r][c] = 0
                if (r==1) & (c==2):
                    answers.append("~A~BC")
                    twoDArray[r][c] = 0
                if (r==1) & (c==3):
                    answers.append("~A~B~C")
                    twoDArray[r][c] = 0
    return answers

def ConvertingTwoDArray(N):
    twoDArray =[]
    N = str(N)
    listN = list(N)
    for i in listN:
        binStr = bin(int(i, 16))[2:]
        twoDArray.append(list(map(int,binStr.zfill(4))))
    return FindExpression(twoDArray)

def FindExpression(TwoDArray):
    answers = []
    answers = FindGroupsOfFour(TwoDArray,answers)
    answers = FindGroupsOfFourWithWrapAround(TwoDArray,answers)
    answers = FindGroupsOfTwo(TwoDArray,answers)
    answers = FindGroupsOfTwoWithWrap(TwoDArray,answers)
    answers = Singles(TwoDArray,answers)
    answers = "+".join(answers)
    return answers


input = ovcc_grader_strings.readinput()

ovcc_grader_strings.clearoutput()
for line in input:
  N = line[0]
  ovcc_grader_strings.writeoutput(ConvertingTwoDArray(N))