#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdlib>
#include <cstring>
#include <sstream>

#define REP(i, n) for(int i=0;i<(n);++i)
#define REPE(i, n) for(int i=0;i<=(n);++i) 
#define REPA(i, a, b) for(int i=(a);i<(b);++i)
#define REPAE(i, a, b) for(int i=(a);i<=(b);++i) 

using namespace std;

typedef unsigned long long int ULINT;
typedef long long int LINT;
typedef pair<int,int> PPI;

int main() {
	while (1) {
	string str;
	int M, N; cin >> M >> N; cin>>str; char ch = str[1];
	if (M == 0) break;
	vector<string> data;
	vector<string> data2;

	REP (i,M) {
		string str; cin>> str;
		data.push_back(str);
	}
	cin.ignore(1);
	REP (i,M) {
		string str; cin>> str;
		data2.push_back(str);
	}
	
	int lm=-1, tm=-1, rm=-1, bm=-1;
	int lm2=-1, tm2=-1, rm2=-1, bm2=-1;
	REP (i,M) {
		REP (j,N) {
			if (data[i][j] == ch) {
				if (lm==-1 || j<lm) lm=j;
				if (rm==-1 || j>rm) rm=j;
				if (tm==-1 || i<tm) tm=i;
				if (bm==-1 || i>bm) bm=i;
			}
			if (data2[i][j] == ch) {
				if (lm2==-1 || j<lm2) lm2=j;
				if (rm2==-1 || j>rm2) rm2=j;
				if (tm2==-1 || i<tm2) tm2=i;
				if (bm2==-1 || i>bm2) bm2=i;
			}
		}
	}
	int dx = lm2 - lm;
	int dy = tm2 - tm;
	
	REP (i,M) {
		REP (j,N) {
			if (data2[i][j] == ch) {
				data2[i][j] = data[i][j];
			}
	//cout << i << ' ' << j << ' ' << ch << ' ' << data[i][j]  << ' ' << data2[i][j] << endl;
		}
	}
dy *=2; dx*=2;
	REP (i,M) {
		REP (j,N) {
			if (data[i][j] == ch) {
				if (i+dy < M && j+dx < N && i+dy >= 0 && j+dx >= 0)
					data2[i+dy][j+dx] = ch;
			}

		}
	}

	REP (i,M) {
		cout << data2[i] << endl;
	}
	cout << endl;
	

	}

	return 0;
}