#Matthew Modi
#Cary Academy INT-3
#ACSL Contest #3

import fileinput
import sys

veitch_diagram = [
    [['A', 'B', 'G', 'H'], 0],
    [['A', 'B', 'C', 'H'], 0],
    [['E', 'B', 'C', 'H'], 0],
    [['E', 'B', 'G', 'H'], 0],
    [['A', 'B', 'G', 'D'], 0],
    [['A', 'B', 'C', 'D'], 0],
    [['E', 'B', 'C', 'D'], 0],
    [['E', 'B', 'G', 'D'], 0],
    [['A', 'F', 'G', 'D'], 0],
    [['A', 'F', 'C', 'D'], 0],
    [['E', 'F', 'C', 'D'], 0],
    [['E', 'F', 'G', 'D'], 0],
    [['A', 'F', 'G', 'H'], 0],
    [['A', 'F', 'C', 'H'], 0],
    [['E', 'F', 'C', 'H'], 0],
    [['E', 'F', 'G', 'H'], 0],
]

alphabet_transform = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
]

line_num = 0

for input_line in fileinput.input('input.txt'):
    try:
        line_num += 1

        for cell in veitch_diagram:
            cell[1] = 0
        
        terms_raw = input_line.split('+')
        for term in terms_raw:
            term_set_raw = [char for char in term]
            term_set = []
            transform = False
            for char in term_set_raw:
                if transform:
                    term_set.append(alphabet_transform[alphabet_transform.index(char)+4])
                    transform = False
                    continue

                if char in alphabet_transform[:4]:
                    term_set.append(char)
                else:
                    transform = True

            for cell in veitch_diagram:
                if all(term in cell[0] for term in term_set):
                    cell[1] = 1
        
        result = ''
        for i in range(4):
            result += hex(int(''.join([str(bit) for bit in [cell[1] for cell in veitch_diagram[i*4:i*4+4]]]), 2))[2]
        print(str(line_num) + '. ' + result.upper())
    except:
        print('Error on line ' + str(line_num))