/*
 * 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.
 */
package wintadd;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 *
 * @author olesnanik2
 */
public class Dive {
    
    static public char[][] picOne = new char[1000][1000];
    static public char[][] picTwo = new char[1000][1000];
    
    static public boolean[][] falconMaskOne = new boolean[1000][1000];
    
    static public int rows, cols;
    
    static public char falcon;
    
    static public int falconOneRow, falconOneCol, falconTwoRow, falconTwoCol;
    
    public static void main(String [] arguments) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while((line = reader.readLine()) != null) {
            if (line.equals("0 0 ' '")) {
                break;
            }
            
            String [] parts = line.split(" ");
            rows = Integer.parseInt(parts[0]);
            cols = Integer.parseInt(parts[1]);
            falcon = parts[2].charAt(1);
            
            boolean found = false;
            for(int row=0; row<rows; row++) {
                line = reader.readLine();
                for(int col=0; col<cols; col++) {
                    falconMaskOne[row][col] = false;
                    picOne[row][col] = line.charAt(col);
                    if (picOne[row][col] == falcon) {
                        if (!found) {
                            found = true;
                            falconOneRow = row;
                            falconOneCol = col;
                        }
                        falconMaskOne[row][col] = true;
                    }
                }
            }
            
            reader.readLine();
            found = false;
            
            for(int row=0; row<rows; row++) {
                line = reader.readLine();
                for(int col=0; col<cols; col++) {
                    picTwo[row][col] = line.charAt(col);
                    if (picTwo[row][col] == falcon) {
                        if (!found) {
                            found = true;
                            falconTwoRow = row;
                            falconTwoCol = col;
                        }
                    }
                }
            }
            
            reader.readLine();
            
            int offsetOneThreeRow = (falconTwoRow - falconOneRow)*2;
            int offsetOneThreeCol = (falconTwoCol - falconOneCol)*2;
            
            for(int row=0; row<rows; row++) {
                for(int col=0; col<cols; col++) {
                    int r = row-offsetOneThreeRow;
                    int c = col-offsetOneThreeCol;
                    
                    if (r >= 0 && c >= 0 && r < rows && c < cols && falconMaskOne[r][c]) {
                        System.out.print(falcon);
                    } else if (falconMaskOne[row][col]) {
                        System.out.print(picTwo[row][col]);
                    } else {
                        System.out.print(picOne[row][col]);
                    }
                }
                System.out.println();
            }
            
            System.out.println();
        }
    }
}