#include <stdio.h>
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
char bd[1111][1111];
char bd2[1111][1111];
char bd3[1111][1111];
char buff[10];
int main() {
	int n,m;
	while(scanf("%d%d%s", &n, &m, buff) == 3) {
		if(n == 0)
			break;
		char zvire = buff[1];
		REP(i, n) scanf("%s", bd[i]);
		REP(i, n) scanf("%s", bd2[i]);
		int radek1 = -100, sloupec1 = -100, radek2 = -100, sloupec2 = -100;
		REP(i, n) REP(j, m) if(bd[i][j] == zvire) {
			radek1 = i; sloupec1 = j;
			i = n+1; j = m+1;
			break;
		}
		REP(i, n) REP(j, m) if(bd2[i][j] == zvire) {
			radek2 = i; sloupec2 = j;
			i = n+1; j = m+1;
			break;
		}
		REP(i, n) REP(j, m) if(bd[i][j] != zvire) {
			bd3[i][j] = bd[i][j];
		} else if(bd2[i][j] != zvire) {
			bd3[i][j] = bd2[i][j];
		}
		
		REP(i, n) REP(j, m) if(bd2[i][j] == zvire) {
			int ni = i+radek2-radek1, nj = j+sloupec2-sloupec1;
			if(ni >= 0 && ni < n && nj >= 0 && nj < m) {
				bd3[ni][nj] = zvire;
			}
		}
		REP(i, n) printf("%s\n", bd3[i]);
		printf("\n");
	}
	return 0;
}