import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
 * 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.
 */
/**
 *
 * @author cteam069
 */
public class Dive {

    static Pattern REG = Pattern.compile("(\\d+) (\\d+) `(.)`");

    public static void main(String[] args) throws IOException {

       /* Matcher m =REG.matcher("2 2 `X`");
        m.find();
        System.out.println(m.group(1));
        System.out.println(m.group(2));
        System.out.println(m.group(3));
        */
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        while (true) {
            if (!doIt(r)) {
                return;
            }
        }

    }

    public static boolean doIt(BufferedReader r) throws IOException {
        String base = r.readLine();
        if (base.equals("0 0 ` `")) {
            return false;
        }
     //   System.out.println(base);
        Matcher m = REG.matcher(base);
        m.find();
        int rows = Integer.parseInt(m.group(1));
        int cols = Integer.parseInt(m.group(2));
        char tar = m.group(3).charAt(0);

        char[][] buffer = new char[rows][cols];
        int fromRow = -1;
        int fromCol = 0;
        int toRow = -1;
        int toCol = 0;
        List<P> patt = new ArrayList<>();

        //A
        for (int row = 0; row < rows; row++) {
            String line = r.readLine();
            for (int cAt = 0; cAt < line.length(); cAt++) {
                char c = line.charAt(cAt);
                if (fromRow == -1 && c == tar) {
                    fromRow = row;
                    fromCol = cAt;
                
                } else {
                    buffer[row][cAt] = c;
                }
            }
        }
        
        r.readLine();

        //B
        for (int row = 0; row < rows; row++) {
            String line = r.readLine();
            for (int cAt = 0; cAt < line.length(); cAt++) {
                char c = line.charAt(cAt);
                if (toRow == -1 && c == tar) {
                    toRow = row;
                    toCol = cAt;
                    patt.add(new P(row, cAt));
                } else if (c == tar) {
                    patt.add(new P(row, cAt));
                }
                else if (c != tar) {
                    buffer[row][cAt] = c;
                }
            }
        }
      //  System.out.println(patt);
        r.readLine();

      /*  System.out.println("buff");
        for(int i=0; i<rows; i++){
            System.out.println(new String(buffer[i]));
        }
        System.out.println("");*/
        
        int dRow = toRow - fromRow;
        int dCol = toCol - fromCol;
      //  System.out.println("d:"+dRow+" "+dCol);
        for (P p : patt) {
            int pRow = p.row + dRow;
            int pCol = p.col + dCol;
            if (pRow >= 0 && pCol >= 0 && pRow < rows && pCol < cols) {
                buffer[pRow][pCol] = tar;
            }
        }

        for(int i=0; i<rows; i++){
            System.out.println(new String(buffer[i]));
        }
        System.out.println("");
        
        return true;
    }

    private static class P {

        public final int row;
        public final int col;

        public P(int row, int col) {
            this.row = row;
            this.col = col;
        }

        @Override
        public String toString() {
            return "("+row+","+col+")";
        }

        
        
    }

}