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

using namespace std;

int main()
{
	while(true)
	{
		int N,M;
		string cs;
		cin >> N >> M;
		if(N==0) break;
		cin >> cs;
		char c = cs[1];
		
		vector<string> frame1,frame2;
		string line;
		vector<string> output;
		getline(cin,line);
		for(int i=0;i<N;i++)
		{
			getline(cin,line);
			frame1.push_back(line);
			output.push_back(line);
		}
		getline(cin,line);
		for(int i=0;i<N;i++)
		{
			getline(cin,line);
			frame2.push_back(line);
		}
		int f1x =-1,f1y,f2x =-1,f2y;
		for(int i=0;i<N;i++)
		{
			for(int j =0;j<M;j++)
			{
				if(frame1[i][j] != c)
					output[i][j] = frame1[i][j];
				else if(f1x == -1)
				{
					f1x = i;
					f1y = j;
				}
				
				if(frame2[i][j] != c)
					output[i][j] = frame2[i][j];
				else if(f2x == -1)
				{
					f2x = i;
					f2y = j;
				}
			}
		}
		int diffx = f2x - f1x;
		int diffy = f2y - f1y;

		
		for(int i=0;i<N;i++)
		{
			for(int j =0;j<M;j++)
			{
				if(frame2[i][j] == c && i+diffx <N && i+diffx >=0 && j+diffy <M && j+diffy >=0)
					output[i+diffx][j+diffy] = c;
			}
		}
		for(int i=0;i<N;i++)
		{
			cout <<output[i] <<'\n';
		}
		cout << '\n';
		
	}
	return 0;
}