# Lance Bae
# Bergen County Academies
# Intermediate

def make_grid(grid):
    for i in range(4):
        grid.append([0] * 4)

def intersection(list1, list2): 
    list3 = [value for value in list1 if value in list2] 
    return list3

def is_in(str1):
    i = 0
    result = []
    while i < len(str1):
        if str1[i] == '~':
            result.append(str1[i:i + 2])
            i += 2
        else:
            result.append(str1[i])
            i += 1
    return result

def convert_to_hex(grid):
    result = ""
    hex_dict = {10 : 'A', 11 : 'B', 12 : 'C', 13 : 'D', 14 : 'E', 15 : 'F'}
    for line in grid:
        curr_val = 0
        curr_val += line[0] * 8
        curr_val += line[1] * 4
        curr_val += line[2] * 2
        curr_val += line[3]
        result += hex_dict.get(curr_val, str(curr_val))
    return result


fin = open("3int_sampledata.txt", 'r')

commands = []
counter = 0

for line in fin:
    commands.append(line.strip('\n'))
    counter += 1

vert_pos = {'A' : [0, 1], '~A' : [2, 3], '~C' : [0, 3], 'C' : [1, 2]}
horiz_pos = {'B' : [0, 1], '~B' : [2, 3], '~D' : [0, 3], 'D' : [1, 2]}

for i in range(0, counter):
    curr_line = commands[i]
    curr_line = curr_line.split('+')
    vietch = []
    make_grid(vietch)
    for curr in curr_line:
        curry_restrictions = [0, 1, 2, 3]
        currx_restrictions = [0, 1, 2, 3]
        bools = is_in(curr)
        for j in vert_pos.keys():
            if j in bools:
                curry_restrictions = intersection(curry_restrictions, vert_pos[j])
        for j in horiz_pos.keys():
            if j in bools:
                currx_restrictions = intersection(currx_restrictions, horiz_pos[j])
        for j in curry_restrictions:
            for k in currx_restrictions:
                vietch[k][j] = 1
    print(str(i + 1) + '. ' + convert_to_hex(vietch))