#include <string>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

typedef struct falcon
{
	int x;
	int y;
} Falcon;

int main(int argc, char ** argv)
{
	while (true)
	{
		int m, n;
		char c, aux;
		
		cin >> m >> n >> aux >> c;
		
		if (m == 0 && n == 0 && c == '\'') break;
		cin >> aux;
		
		vector<Falcon> falcons;
		Falcon falconOld, falconNew;
		bool set = false;
		bool set2 = false;
		char ** frame = new char*[m];
		for (int i = 0; i < m; i++) frame[i] = new char[n];

		
		for (int i = 0; i < m ; i++)
		{
			for (int j = 0; j < n; j++)
			{
				scanf(" %c", &aux);
				if (aux == c)
				{
					if (!set)
					{
						set = true;
						falconOld.x = j;
						falconOld.y = i;
					}
				}
				else frame[i][j] = aux;
			}	
		}

		for (int i = 0; i < m ; i++)
		{
			for (int j = 0; j < n; j++)
			{
				scanf(" %c", &aux);
				if (aux == c)
				{
					if (!set2)
					{
						set2 = true;
						falconNew.x = j;
						falconNew.y = i;
					}
					Falcon f;
					f.x = j;
					f.y = i;
					falcons.push_back(f);
				}
				else frame[i][j] = aux;
			}	
		}
	
		int moveX = falconNew.x - falconOld.x;
		int moveY = falconNew.y - falconOld.y;

		for(auto it = falcons.begin(); it != falcons.end(); ++it) if ((*it).x + moveX < n && (*it).x + moveX >= 0 && (*it).y + moveY < m && (*it).y + moveY >= 0) frame[(*it).y + moveY][(*it).x + moveX] = c;

		for (int i = 0; i < m ; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cout << frame[i][j];
			}	
			cout << endl;
		}
	}
	
	return 0;
}