# Chris Chen
# Legion of Learners
# Senior Division
# Contest #3 2019-2020

import sys

def c(l, n):
    return [l[i][n] for i in range(4)]

with open('testdata.txt') as sys.stdin:
    for it in range(5):
        grid = [list(bin(int(i, 16))[2:].zfill(4)) for i in input().strip()]
        # print(grid)
        output = []
        for row in range(4):
            if grid[row] == list('1111'):
                if grid[(row+1)%4] == list('1111'):
                    output += [['B', 'D', '~B', 'D~'][row]]
                    grid[row] = list('0000')
                    grid[(row+1)%4] = list('0000')
        for col in range(4):
            if c(grid, col) == list('1111'):
                if c(grid, (col+1)%4) == list('1111'):
                    output += [['A', 'C', '~A', '~C'][col]]
                    for i in range(4):
                        grid[i][col] = '0'
                        grid[i][(col+1)%4] = '0'
        for i in range(4):
            if grid[i] == list('1111'):
                output += [['B~D', 'BD', '~BD', '~B~D'][i]]
                grid[i] = list('0000')
            if c(grid, i) == list('1111'):
                output += [['A~C', 'AC', '~AC', '~A~C'][i]]
                for j in range(4):
                    grid[j][i] = '0'
        for i in range(3):
            for j in range(3):
                if grid[i][j] == grid[i][(j+1)%4] == grid[(i+1)%4][j] == grid[(i+1)%4][(j+1)%4] == '1':
                    output += [[
                        ['AB', 'BC', 'A~B', 'A~D'],
                        ['AD', 'CD', '~AD', '~CD'],
                        ['A~B', 'C~B', '~A~B', '~B~C'],
                        ['A~D', 'C~D', '~A~D', '~C~D']
                    ][i][j]]
                    grid[i][j] = '0'
                    grid[i][(j+1)%4] = '0'
                    grid[(i+1)%4][j] = '0'
                    grid[(i+1)%4][(j+1)%4] = '0'
        j = 3
        for i in range(3):
            if grid[i][j] == grid[i][(j+1)%4] == grid[(i+1)%4][j] == grid[(i+1)%4][(j+1)%4] == '1':
                output += [[
                    ['AB', 'BC', 'A~B', 'A~D'],
                    ['AD', 'CD', '~AD', '~CD'],
                    ['A~B', 'C~B', '~A~B', '~B~C'],
                    ['A~D', 'C~D', '~A~D', '~C~D']
                ][i][j]]
                grid[i][j] = '0'
                grid[i][(j+1)%4] = '0'
                grid[(i+1)%4][j] = '0'
                grid[(i+1)%4][(j+1)%4] = '0'
        i = 3
        for j in range(3):
            if grid[i][j] == grid[i][(j+1)%4] == grid[(i+1)%4][j] == grid[(i+1)%4][(j+1)%4] == '1':
                output += [[
                    ['AB', 'BC', 'A~B', 'A~D'],
                    ['AD', 'CD', '~AD', '~CD'],
                    ['A~B', 'C~B', '~A~B', '~B~C'],
                    ['A~D', 'C~D', '~A~D', '~C~D']
                ][i][j]]
                grid[i][j] = '0'
                grid[i][(j+1)%4] = '0'
                grid[(i+1)%4][j] = '0'
                grid[(i+1)%4][(j+1)%4] = '0'
        i, j = 3, 3
        if grid[i][j] == grid[i][(j+1)%4] == grid[(i+1)%4][j] == grid[(i+1)%4][(j+1)%4] == '1':
            output += [[
                ['AB', 'BC', 'A~B', 'A~D'],
                ['AD', 'CD', '~AD', '~CD'],
                ['A~B', 'C~B', '~A~B', '~B~C'],
                ['A~D', 'C~D', '~A~D', '~C~D']
            ][i][j]]
            grid[i][j] = '0'
            grid[i][(j+1)%4] = '0'
            grid[(i+1)%4][j] = '0'
            grid[(i+1)%4][(j+1)%4] = '0'
        for i in range(4):
            for j in range(3):
                if grid[i][j] == grid[i][(j+1)%4] == '1':
                    output += [[
                        ['AB~D', 'BC~D', '~AB~D', 'B~C~D'],
                        ['ABD', 'BCD', '~ABD', 'B~CD'],
                        ['A~BD', '~BCD', '~A~BD', '~B~CD'],
                        ['A~B~D', '~BC~D', '~A~B~D', '~B~CD']
                    ][i][j]]
                    grid[i][j] = '0'
                    grid[i][(j+1)%4] = '0'
        for j in range(4):
            for i in range(3):
                if grid[i][j] == grid[(i+1)%4][j] == '1':
                    output += [[
                        ['AB~C', 'ABC', '~ABC', '~AB~C'],
                        ['A~CD', 'ACD', '~ACD', '~A~CD'],
                        ['A~B~C', 'A~BC', '~A~BC', '~A~B~C'],
                        ['A~C~D', 'AC~D', '~AC~D', '~A~C~D']
                    ][i][j]]
                    grid[(i+1)%4][j] = '0'
                    grid[i][j] = '0'
        j = 3
        for i in range(4):
            if grid[i][j] == grid[i][(j+1)%4] == '1':
                output += [[
                    ['AB~D', 'BC~D', '~AB~D', 'B~C~D'],
                    ['ABD', 'BCD', '~ABD', 'B~CD'],
                    ['A~BD', '~BCD', '~A~BD', '~B~CD'],
                    ['A~B~D', '~BC~D', '~A~B~D', '~B~CD']
                ][i][j]]
                grid[i][j] = '0'
                grid[i][(j+1)%4] = '0'
        i = 3
        for j in range(4):
            if grid[i][j] == grid[(i+1)%4][j] == '1':
                output += [[
                    ['AB~C', 'ABC', '~ABC', '~AB~C'],
                    ['A~CD', 'ACD', '~ACD', '~A~CD'],
                    ['A~B~C', 'A~BC', '~A~BC', '~A~B~C'],
                    ['A~C~D', 'AC~D', '~AC~D', '~A~C~D']
                ][i][j]]
                grid[i][j] = '0'
                grid[(i+1)%4][j] = '0'
        for i in range(4):
            for j in range(4):
                if grid[i][j] == '1':
                    output += [f'{"~" if j in [2, 3] else ""}A{"~" if i in [2, 3] else ""}B{"~" if j in [0, 3] else ""}C{"~" if i in [0, 3] else ""}D']
                    grid[i][j] = '0'
        print('+'.join(output))