/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 *
 * @author tym10
 */
public class Dive {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void main(String[] args) throws IOException {
        char [] buffer;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        buffer = in.readLine().toCharArray();
        
        while (!Arrays.equals(buffer, "0 0 ' '".toCharArray())) {
            String[] ex = String.copyValueOf(buffer).split(" ");
            int y = Integer.parseInt(ex[0]);
            int x = Integer.parseInt(ex[1]);
            char falcon = ex[2].charAt(1);
            char[][][] maps = new char[3][y][x];
            boolean found = false;
            int fx = -1;
            int fy = -1;
            int dx = Integer.MIN_VALUE;
            int dy = Integer.MIN_VALUE;
            
            for (int i = 0; i < y; i++) {
                maps[0][i] = in.readLine().toCharArray();
            }
            
            in.readLine();
            
            for (int i = 0; i < y; i++) {
                maps[1][i] = in.readLine().toCharArray();
            }
            
            for (int i = 0; i < y; i++) {
                for (int j = 0; j < x; j++) {
                    if (maps[0][i][j] != falcon) {
                        maps[2][i][j] = maps[0][i][j];
                    } else {
                        if (!found) {
                            fy = i;
                            fx = j;
                            found = true;
                        }
                        maps[2][i][j] = maps[1][i][j];
                    }
                }
            }
            
            if (found) {
                for (int i = 0; i < y; i++) {
                    for (int j = 0; j < x; j++) {
                        if (maps[1][i][j] == falcon) {
                            dy = i - fy;
                            dx = j - fx;
                            break;
                        }
                    }
                    if (dx != Integer.MIN_VALUE) {
                        break;
                    }
                }
            }
            
            for (int i = 0; i < y; i++) {
                for (int j = 0; j < x; j++) {
                    if (maps[1][i][j] == falcon) {
                        int tempy = i + dy;
                        int tempx = j + dx;
                        if (!((tempy < 0 || tempy >= y) || (tempx < 0 || tempx >= x))) {
                            maps[2][tempy][tempx] = falcon;
                        }
                    }
                }
            }
            
            for (int i = 0; i < y; i++) {
                for (int j = 0; j < x; j++) {
                    System.out.print(maps[2][i][j]);
                    if (j == x-1)
                        System.out.print("\n");
                }
            }
            
            System.out.print("\n");
            
            in.readLine();
            buffer = in.readLine().toCharArray();
        }
    }
    
}