/*
 * 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 javaapplication1;

import java.util.Scanner;

/**
 *
 * @author klempai3
 */
public class OWL {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        char[][] mapA = new char[1001][1001];
        char[][] mapB = new char[1001][1001];
        
        char[][] vysledok = new char[1001][1001];
        
        int x = 0;
        int y = 0;
        while(true){
            x = sc.nextInt();
            y = sc.nextInt();
            
            if (x==0) {
                break;
            }
            
            boolean[][] map1 = new boolean[1001][1001];
            boolean[][] map2 = new boolean[1001][1001];
            
            char orol = sc.nextLine().trim().charAt(1);
            for(int i = 0; i<x;i++){
                String line = sc.nextLine();
                for(int j = 0; j<y;j++){
                    mapA[i][j] = line.charAt(j);
                    if(mapA[i][j]==orol){
                        map1[i][j]=true;
                    }
                }
            }
            
            sc.nextLine();
            
            for(int i = 0; i<x;i++){
                String line = sc.nextLine();
                for(int j = 0; j<y;j++){
                    mapB[i][j] = line.charAt(j);
                    if(mapB[i][j]==orol){
                        map2[i][j]=true;
                    }
                }
            }
            
            for(int i = 0; i<x;i++){
                for(int j = 0; j<y;j++){
                    if(mapA[i][j]==orol){
                        vysledok[i][j] = mapB[i][j];
                    }else{
                        vysledok[i][j] = mapA[i][j];
                    }
                }
            }
            
            int upA = 1002;
            int downA = 0;
            int rightA = 0;
            int leftA = 1002;
            
            int upB = 1002;
            int downB = 0;
            int rightB = 0;
            int leftB = 1002;
            
            for(int i = 0; i<x;i++){ 
                for(int j = 0; j<y;j++){
                    if(map1[i][j]){
                        if(upA > i){
                            upA = i;
                        }
                        if(leftA > j){
                            leftA = j;
                        }
                        if(downA < i){
                            downA = i;
                        }
                        if(rightA < j){
                            rightA = j;
                        }
                    }
                }
            }
            
            for(int i = 0; i<x;i++){ 
                for(int j = 0; j<y;j++){
                    if(map2[i][j]){
                        if(upB > i){
                            upB = i;
                        }
                        if(leftB > j){
                            leftB = j;
                        }
                        if(downB < i){
                            downB = i;
                        }
                        if(rightB < j){
                            rightB = j;
                        }
                    }
                }
            }
            
            int left = leftB - leftA;
            int right = rightB - rightA;
            int up = upB - upA;
            int down = downB - downA;
            
            int X = Math.abs(right) > Math.abs(left) ? right : left;
            int Y = Math.abs(up) > Math.abs(down) ? up : down;
            
            boolean[][] map3 = new boolean[1001][1001];
            
            for(int i = 0; i<x;i++){ 
                for(int j = 0; j<y;j++){
                    if(0 <= i+Y && i+Y < x && 0 <= j+X && j+X < y) {
                        map3[i+Y][j+X] = map2[i][j];
                    }
                }
            }
            
            //VYPIS VYSLEDKU
            for(int i = 0; i<x;i++){ 
                for(int j = 0; j<y;j++){
                    if (map3[i][j]) {
                        System.out.print(orol);
                    } else {
                        System.out.print(vysledok[i][j]);
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}