import sys

def read_frame(rows, cols):
    frame = []
    for r in range(0, rows):
        frame.append(list(input()))
    return frame

def find_falcon(frame, falcon):
    for r,row in enumerate(frame):
        for c,char in enumerate(row):
            if char == falcon:
                return (r, c)

def fff(frame):
    for row in frame:
        print(''.join(row))

while True:
    line = input()
    #print(line)
    rows, cols, char = line.split(maxsplit=2)
    rows = int(rows)
    cols = int(cols)
    falcon = char[1]
    if rows == 0 and cols == 0 and falcon == ' ':
        break
    # TODO: refactor more
    frames = []
    frames.append(read_frame(rows, cols))
    input()
    # TODO: refactor more
    frames.append(read_frame(rows, cols))
    input()
    falcons = [find_falcon(frame, falcon) for frame in frames]
    neco = (falcons[1][0] - falcons[0][0], falcons[1][1] - falcons[0][1])
    #print(neco)
    
    # TODO: refactor more
    frame = [ [None] * cols for r in range(rows) ]
    for r in range(rows):
        for c in range(cols):
            if frames[0][r][c] != falcon:
                frame[r][c] = frames[0][r][c]
            elif frames[1][r][c] != falcon:
                frame[r][c] = frames[1][r][c] #TODO refactor
    # TODO: refactor more
    for r in range(rows):
        for c in range(cols):
            if frames[1][r][c] == falcon:
                fr = r + neco[0]
                fc = c + neco[1]
                #print(fr, fc)
                if fr >= 0 and fr < rows and fc >= 0 and fc < cols:
                    frame[fr][fc] = falcon 

    fff(frame)
    print()