#include <iostream>
#include <cstdio>
#include <sstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
	long long a, b;
	string s;
	while (cin >> a >> b >> s) {
		
		if(a==0 && b==0 ) {
			break;
		}
		char d = s[1];
//		cout << s << " " << d << "\n";
		getline(cin, s);
		vector<string> v1(a), v2(a);
		for(long long i = 0; i<a; i++) {
			getline(cin, v1[i]);
		}
		getline(cin, s);
		for(long long i = 0; i<a; i++) {
			getline(cin, v2[i]);
		}
		long long x1=-1, y1=-1, x2=-1, y2=-1;
		for(long long i = 0; i<a; i++) {
			for(long long j = 0; j<b; j++) {
				if(v1[i][j] == d) {
					if(x1<0) {
						x1 = i;
						y1 = j;
					}
					v1[i][j] = 0;
				}
				if(v2[i][j] == d) {
					if(x2<0) {
						x2 = i;
						y2 = j;
					}
					v2[i][j] = 0;
				}
			}
		}
		long long s1 = x2-x1, s2=y2-y1;
		for(long long i =0; i<a; i++) {
			for(long long j = 0; j<b; j++) {
				if(v2[i][j] == 0) {
					long long nx = i+s1, ny= j+s2;
					//cout << nx << " " << ny << "\n";
					if(nx>=0 && nx <a && ny >=0 && ny<b) {
					//	cout << nx << " " << ny << "\n";
						v1[nx][ny]=d;
					}
				}
			}
		}
//			for(int i = 0; i<a; i++) {
//			cout << v1[i] << "\n";
//		}
//		for(int i = 0; i<a; i++) {
//			cout << v2[i] << "\n";
//		}
	
		for(long long i = 0; i<a; i++) {
			for(long long j = 0; j<b; j++) {
				if(v1[i][j]==d) {
					cout << d;
				}
				else if(v2[i][j] == 0){
					cout << v1[i][j];
				}
				else {
					cout << v2[i][j];
				}
			}
			cout << "\n";
		}
		cout << "\n";
	}
}