#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define DEBUG(x) cout << ">" << #x << ": " << x << endl
typedef vector<string> vs;

void first(const vs & v, char c, int & iout, int & jout) {
	for ( int i = 0 ; i < v.size() ; ++i )
		for ( int j = 0 ; j < v[0].size(); ++j )
		{
			if ( v[i][j] == c )
			{
				iout = i;
				jout = j;
				return;
			}
		}
}

int main() {
	for ( ;; ) {
		int M, N;
		char C;
		string line;
		vector<string> frame1, frame2, out;
		scanf("%d %d \'%c\'\n", &M, &N, &C);
		if ( !M && !N && C == ' ' )
			break;
		for ( int i = 0 ; i < M ; ++i )
		{
			getline(cin, line);
			frame1.push_back(line);
		}
		getline(cin, line);
		for ( int i = 0 ; i < M ; ++i )
		{
			getline(cin, line);
			frame2.push_back(line);
		}
		out = frame2;
		int fromx, fromy, tox, toy;
		first(frame1, C, fromy, fromx);
		first(frame2, C, toy, tox);
		int diffx = tox-fromx;
		int diffy = toy-fromy;
		for ( int i = 0 ; i < M ; ++i )
			for ( int j = 0 ; j < N; ++j )
			{
				int oldx = j - diffx;
				int oldy = i - diffy;
				if ( oldx < N && oldx >= 0 &&
					oldy < M && oldy >= 0 &&
					frame2[oldy][oldx] == C )
					out[i][j] = C;
				else if ( frame1[i][j] != C )
					out[i][j] = frame1[i][j];
				else if ( frame2[i][j] != C )
					out[i][j] = frame2[i][j];
			}
		for ( int i = 0 ; i < M ; ++i )
			cout << out[i] << endl;
		cout << endl;
	}
return 0;
}