import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

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

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String tmp;
        while ((tmp = br.readLine()).compareTo("0 0 " + (char)39 + " " + (char)39) != 0) {
            String[] line = tmp.split(" ");
            int height = Integer.parseInt(line[0]);
            int width = Integer.parseInt(line[1]);
            
            
            char symbol = line[2].split("" + (char)39)[1].charAt(0);

            ArrayList<Point> position = new ArrayList<>();

            char[][] map = new char[height][width];

            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    map[i][j] = (char) 0;
                }
            }

            
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    char c = (char) br.read();
                    if (c == symbol) {
                        position.add(new Point(j, i));
                    } else {
                        map[i][j] = c;
                    }
                }
                while(br.read() == ' '){}
            }
            //br.readLine();
while(br.read() == ' '){}
            int dx = 0;
            int dy = 0;

            boolean lala = false;
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    char c = (char) br.read();
                    if (map[i][j] == (char) 0) {
                        map[i][j] = c;
                    } else if (c == symbol && !lala) {
                        lala = true;
                        dx = j - position.get(0).x;
                        dy = i - position.get(0).y;
                    }
                }
                while(br.read() == ' '){}
                //br.read();
            }
            
            for (Point p : position) {
                p.x += 2 * dx;
                p.y += 2 * dy;
                if ((p.x < width && p.x >= 0) && (p.y < height && p.y >= 0)) {
                    map[p.y][p.x] = symbol;
                }
            }
            
            

            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    System.out.print(map[i][j]);
                }
                System.out.println();
            }
            System.out.println();

            //br.readLine();
            while(br.read() == ' '){}
        }

    }

}