#include <iostream>
using namespace std;

typedef struct {
	char** frame;
	int w;
	int h;
} frame;

void initFrame(frame &f, int w, int h) {
	f.w = w;
	f.h = h;
	f.frame = new char*[h];
	for(int i = 0; i < h; i++) {
		f.frame[i] = new char[w];

		char c;
		for(int j = 0; j < w; j++) {
			cin >> c;
			f.frame[i][j] = c;
		}
	}
}

void printFrame(frame &frame) {
	for(int i = 0; i < frame.h; i++) {
		for(int j = 0; j < frame.w; j++) {
			cout << frame.frame[i][j];
		}
		cout << "\n";
	}
}

typedef struct {
	int x, y;
} Coord;

Coord findFirst(frame &f, char C) {
	for(int i = 0; i < f.h; i++) {
		for(int j = 0; j < f.w; j++) {
			if(f.frame[i][j] == C) {
				Coord coord = {i, j};
				return coord;
			}
		}
	}
	Coord coord = {0, 0};
	return coord;
}

int main() {
while(true) {
	frame first, last;

	int w, h;
	char empty, C;
	cin >> h >> w;
	cin >> empty >> C >> empty;

	if(w == 0 && h == 0 && C == '\'') {
		break;
	}

	initFrame(first, w, h);
	initFrame(last, w, h);

//	printFrame(first);
//	printFrame(last);

	
	Coord a = findFirst(first, C);
	Coord b = findFirst(last, C);

	//cout << a.x << " " << a.y << endl;
	//cout << b.x << " " << b.y << endl;

	Coord shift =  {b.x - a.x, b.y - a.y};
	//cout <<"POSUNUTI: " << shift.x << " " << shift.y << endl;



	frame next;
	next.w = w;
	next.h = h;
	next.frame = new char*[h];
	for(int i = 0; i < h; i++) {
		next.frame[i] = new char[w];
	}

//	cout << shift.x << " " << shift.y << endl;
	for(int i = 0; i < last.h; i++) { 
		for (int j = 0; j < last.w; j++){
			//if(first.frame[i][j] == last.frame[i][j] && last.frame[i][j] !=C) {
			//} else {
			//cout << last.frame[i][j] << endl;
			if(last.frame[i][j] == C) {
				Coord newPos = {i + shift.x, j + shift.y};
				//cout << newPos.x << " " << newPos.y << endl;
				if(newPos.x >= 0 && newPos.y >= 0 && newPos.x < last.h && newPos.y < last.w) {
				//	cout << "writin'" << endl;
					next.frame[newPos.x][newPos.y] = C;
				}
				next.frame[i][j] = first.frame[i][j];
			} else {
				next.frame[i][j] = last.frame[i][j];
			}
		}
	}

	printFrame(next);
	cout << endl;
}



	return 0;
}