import java.util.Scanner;


public class Dive {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		int y = sc.nextInt();
		int x = sc.nextInt();       //x pocet sloupcu, y/pocet radku
		String s=sc.next();
		char p;
		if (s.length()!=3){
			p=' ';
		}
		else {
			p=s.charAt(1);
		}
	
		
		while ((x!=0)&&(y!=0)&&(p!=' ')) {
			boolean hotovo=false;
			int orex=0;
			int orey=0;
			char[][]pole1=new char[y][x];
			char[][]pole2=new char[y][x];
			char[][]pole3=new char[y][x];
			
			
			for (int j=0;j<y;j++){
				String pom = sc.next();
				for (int i=0;i<x;i++){
					pole1[j][i]=pom.charAt(i);
					if ((pole1[j][i]==p)&&(!hotovo)){
						orex=i;
						orey=j;
						hotovo=true;
					}
				}
							}
			hotovo = false;int radek=0;
			for (int j=0;j<y;j++){
				String pom = sc.next();
				for (int i=0;i<x;i++){
					pole2[j][i]=pom.charAt(i);
					pole3[j][i]=pom.charAt(i);
					if ((pole2[j][i]==p)){
						if(!hotovo) {
							orex=-orex+i;
							orey=-orey+j;
							radek=j;
							hotovo=true;
						}
				}
			}}
				
			for (int j=radek;j<y;j++){
				for (int i=0;i<x;i++){
					if(pole2[j][i]==p) {
						if (((i+orex<x)&&(j+orey<y))&&((i+orex>=0)&&(j+orey>=0)))
							pole3[j+orey][i+orex]=p;
						pole3[j][i]=pole1[j][i];
					
				}
			}}


			for (int j =0; j<y;j++){
				for (int i =0; i<x;i++){
					System.out.print(pole3[j][i]);
				}
				System.out.println();
			}
			
			
			y = sc.nextInt();
			x = sc.nextInt();
			s=sc.next();
			 
			if (s.length()!=3){
				p=' ';
			}
			else {
				p=s.charAt(1);
			}
			System.out.println();
		}}
	}