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

public class Dive {
    public static void main (String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line="";
        String[] head;
        int x, y;
        char ch;
        String[] map1;
        String[] map2;
        char[][] result;
        
        LinkedList<Point> pos;
        int offsetX = 0;
        int offsetY = 0; // druhy - prvy
        
        while(true){
            line = br.readLine();
            if (line.equals("0 0 ' '")) break;
            head = line.split(" ");
            x = Integer.parseInt(head[0]); //pocet riadkov
            y = Integer.parseInt(head[1]); //      stpcov
            ch = head[2].charAt(1);
            
            
            map1 = new String[x];
            map2 = new String[x];
            
            for (int i = 0; i < x; i++) {
                map1[i] = br.readLine();
            }
            br.readLine();
            for (int i = 0; i < x; i++) {
                map2[i] = br.readLine();
            }
            br.readLine();
            /*
            for (int i = 0; i < x; i++) {
                System.out.println(map1[i]);
            }
            System.out.println("");
            for (int i = 0; i < x; i++) {
                System.out.println(map2[i]);
            }*/
            
            pos = new LinkedList<Point>();
            
            for (int i = 0; i < x; i++) {
                //System.out.println(map1[i]);
                for (int j = 0; j < y; j++) {
                    if(map1[i].charAt(j) == ch)
                        pos.add(new Point(i, j));
                }
            }
            
            A:for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                    if(map2[i].charAt(j) == ch)  {
                        offsetX = i - pos.getFirst().x;
                        offsetY = j - pos.getFirst().y;
                        break A;
                    }
                }
            }
            
            result = new char[x][y];
            for (int i = 0; i < x; i++) {
                result[i] = map1[i].toCharArray();
            }
            
            int newX = 0;
            int newY = 0;
            
            for (Point p : pos) {
                result[p.x][p.y] = map2[p.x].charAt(p.y);
            }
            //System.out.println("off " + offsetX + " " + offsetY);
            for (Point p : pos) {
                newX = (p.x + 2*offsetX);
                newY = (p.y + 2*offsetY);
                //System.out.println(newX + " " + newY + "            " + p.x + " " + p.y );
                if(newX >= x || newX < 0 || newY >= y || newY < 0) continue;
                result[newX][newY] = ch;
            }
            
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                    System.out.print(result[i][j]);
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
    
    private static class Point{
        public int x;
        public int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}