
moves = { (1, 1, 1): 0,
          (1, 1, 0): 1,
          (1, 0, 1): 2,
          (1, 0, 0): 3,
          (0, 1, 1): 4,
          (0, 1, 0): 5,
          (0, 0, 1): 6,
          (0, 0, 0): 7}

mask = {"X": 1, ".": 0}

def binary(num):
    nums = []

    while num > 0:

        nums.append( num % 2 )
        num //= 2

    for i in range( 8 - len(nums) ):
        nums.append(0)

    nums.reverse()
    return nums

def get(i, mat):

    second = mask[ mat[i] ]

    if i - 1 < 0:
        first = 0
    else:
        first = mask[ mat[i - 1] ]

    if i + 1 >= len(mat):
        third = 0
    else:
        third = mask[ mat[i + 1] ]

    return first, second,  third

def evalu(mat, rule):

    res = ""
    for i in range(len(mat)):

        a, b, c = get(i, mat)
        which = moves[ (a, b, c) ]
        res += "X" if rule[which] == 1 else "."

    return res



if __name__ == "__main__":

    line = [int(x) for x in input().split()]
    rule, iterations = line[0], line[1]
    initial = input()

    rule = binary(rule)

    for it in range(iterations):
        initial = evalu(initial, rule)
        print(initial)

