N, C = map(int, input().split())

letter_table = {
    'a': [0,1],
    'b': [0,2],
    'c': [0,3],
    'd': [0,4],
    'e': [0,5],
    'f': [0,6],
    'g': [0,7],
    'h': [1,2],
    'i': [1,3],
    'j': [4,6],
    'k': [1,4],
    'l': [1,5],
    'm': [1,6],
    'n': [1,7],
    'o': [2,3],
    'p': [2,4],
    'q': [2,5],
    'r': [2,6],
    's': [2,7],
    't': [3,4],
    'u': [3,5],
    'v': [4,7],
    'w': [5,6],
    'x': [5,7],
    'y': [3,6],
    'z': [6,7]
}

def create_letter(letter):
    table = [
""".........
.........
.........
.........
....*....
....#....
....#....
....#....
.........
""","""
.........
.........
.........
.........
....*....
...#.....
..#......
.#.......
.........
""","""
.........
.........
.........
.........
.###*....
.........
.........
.........
.........
""","""
.........
.#.......
..#......
...#.....
....*....
.........
.........
.........
.........
""","""
.........
....#....
....#....
....#....
....*....
.........
.........
.........
.........
""","""
.........
.......#.
......#..
.....#...
....*....
.........
.........
.........
.........
""","""
.........
.........
.........
.........
....*###.
.........
.........
.........
.........
""","""
.........
.........
.........
.........
....*....
.....#...
......#..
.......#.
.........
"""
    ]
    newTable = []
    for x in table:
        lines = x.strip().splitlines()
        newTable.append(list(lines))

    hand1, hand2 = letter_table[letter]

    for y in range(9):
        for x in range(9):
            if x == y == 4:
                print('*', end="")
            elif newTable[hand1][y][x] == '#' or newTable[hand2][y][x] == '#':
                print('#', end="")
            else:
                print('.', end="")
        print()

def parse_letter():
    lines = [input() for _ in range(9)]
    hands = []
    if lines[3][3] == '#':
        hands.append(3)
    if lines[3][4] == '#':
        hands.append(4)
    if lines[3][5] == '#':
        hands.append(5)
    if lines[4][3] == '#':
        hands.append(2)
    if lines[4][5] == '#':
        hands.append(6)
    if lines[5][3] == '#':
        hands.append(1)
    if lines[5][4] == '#':
        hands.append(0)
    if lines[5][5] == '#':
        hands.append(7)
    hands.sort()
    for letter, positions in letter_table.items():
        if positions == hands:
            return letter

def caesar(letter):
    return  chr((ord(letter) - ord('a') + C) % 26 + ord('a'))

for _ in range(N):
    input_letter = parse_letter()
    output_letter = caesar(input_letter)
    create_letter(output_letter)
