#include <iostream>
#include <vector>
using namespace std;

struct Point {
	int x;
	int y;
};

int main() {
	bool first = true;
	int M, N;
	char falcon, c;
	char pic[1000][1000];
	vector<Point> falc;
	while(cin >> M >> N >> c >> falcon >> c) {
		if(!first){
			cout << endl;
		}else{
			first = false;		
		}
		falc.clear();
		cin.ignore();
		if (M == 0) break;
		for (int m = 0; m < M; m++) {
			for (int n = 0; n < N; n++) {
				cin >> c;
				pic[m][n] = c;
				if (c == falcon) {
					Point tmp;
					tmp.x = m;
					tmp.y = n;
					falc.push_back(tmp);
				}
			}
			cin.ignore();
		}
		cin.ignore();
		bool shiftFound = false;
		int k = 0;
		int shiftx = 0;
		int shifty = 0;
		for (int m = 0; m < M; m++) {
			for (int n = 0; n < N; n++) {
				cin >> c;
				if (!shiftFound && c == falcon) {
						shiftx = m - falc[0].x;
						shifty = n - falc[0].y;
						shiftFound = true;
				}
				if (m == falc[k].x && n == falc[k].y) {
					pic[m][n] = c;
					k++;					
				}
			}
			cin.ignore();			
		}

		for (int i = 0; i < k; i++) {
			int newx, newy;
			newx = falc[i].x + 2*shiftx;
			newy = falc[i].y + 2*shifty;
			if (newx < 0 || newy < 0 || newx >= M || newy >= N) continue;
			pic[newx][newy] = falcon;
		}

		for (int m = 0; m < M; m++) {
			for (int n = 0; n < N; n++) {
				cout << pic[m][n];
			}
			cout << endl;
		}		
	}

	return 0;
}