down = """.........
.........
.........
.........
....*....
....#....
....#....
....#....
.........""".replace("\n", "")

left_down = """.........
.........
.........
.........
....*....
...#.....
..#......
.#.......
.........""".replace("\n", "")

left = """.........
.........
.........
.........
.###*....
.........
.........
.........
.........""".replace("\n", "")

left_top = """.........
.#.......
..#......
...#.....
....*....
.........
.........
.........
.........""".replace("\n", "")

top = """.........
....#....
....#....
....#....
....*....
.........
.........
.........
.........""".replace("\n", "")

right_top = """.........
.......#.
......#..
.....#...
....*....
.........
.........
.........
.........""".replace("\n", "")

right = """.........
.........
.........
.........
....*###.
.........
.........
.........
.........""".replace("\n", "")

right_down = """.........
.........
.........
.........
....*....
.....#...
......#..
.......#.
.........""".replace("\n", "")

def combine(a, b):
    result = ""
    for chr1, chr2 in zip(a, b):
        if chr1 == "*" or chr2 == "*":
            result += "*"
            continue
        if chr1 == "#" or chr2 == "#":
            result += "#"
            continue
        result += "."

    return result

def pretty_print(a):
    counter = 0
    for ch in a:
        print(ch, end="")
        counter += 1
        if counter == 9:
            print()
            counter = 0

ciphered = {
    combine(left_down, down): "a",
    combine(left, down): "b",
    combine(left_top, down): "c",
    combine(top, down): "d",
    combine(down, right_top): "e",
    combine(right, down): "f",
    combine(down, right_down): "g",
    combine(left, left_down): "h",
    combine(left_down, left_top): "i",
    combine(top, right): "j",
    combine(top, left_down): "k",
    combine(left_down, right_top): "l",
    combine(left_down, right): "m",
    combine(left_down, right_down): "n",
    combine(left, left_top): "o",
    combine(left, top): "p",
    combine(left, right_top): "q",
    combine(left, right): "r",
    combine(left, right_down): "s",
    combine(left_top, top): "t",
    combine(left_top, right_top): "u",
    combine(top, right_down): "v",
    combine(right_top, right): "w",
    combine(right_top, right_down): "x",
    combine(left_top, right): "y",
    combine(right, right_down): "z",
}
alphabet = list(ciphered.keys())

line = input().split()
count = int(line[0])
shift = int(line[1])

for _ in range(count):
    lines = [input() for _ in range(9)]
    requested = "".join(lines)
    char = ciphered[requested]
    num = ((ord(char) - 97) + shift) % 26
    pretty_print(alphabet[num])


