#include <iostream>
#include <list>

using namespace std;

int main()
{
    int M, N;
    char C, Q;
    cin >> M;
    while (1)
    {
        if (M == 0)
            return 0;

        cin >> N >> Q >> C >> Q;

        char first[M][N];
        char second[M][N];

        list<int> falconInFirstX = list<int>();
        list<int> falconInFirstY = list<int>();
        int falconInSecondX = -1;
        int falconInSecondY = -1;

        for (int i = 0; i < M; i++)
        {
            for (int j = 0; j < N; j++)
            {
                cin >> first[i][j];
                if ((first[i][j] == C))
                {
                    falconInFirstX.push_back(j);
                    falconInFirstY.push_back(i);
                }
            }
        }
        for (int i = 0; i < M; i++)
            for (int j = 0; j < N; j++)
            {
                cin >> second[i][j];
                if ((falconInSecondX == -1) && (second[i][j] == C))
                {
                    falconInSecondX = j;
                    falconInSecondY = i;
                }
            }

        int changeX = falconInSecondX - falconInFirstX.front();
        int changeY = falconInSecondY - falconInFirstY.front();

        list<int> copyX = falconInFirstX;
        list<int> copyY = falconInFirstY;

        while(!falconInFirstX.empty())
        {
            int x = falconInFirstX.front();
            int y = falconInFirstY.front();
            first[y][x] = second[y][x];
            falconInFirstX.pop_front();
            falconInFirstY.pop_front();
        }

        falconInFirstX = copyX;
        falconInFirstY = copyY;
        while(!falconInFirstX.empty())
        {
            int x = falconInFirstX.front();
            int y = falconInFirstY.front();
            falconInFirstX.pop_front();
            falconInFirstY.pop_front();
            int newX = x + 2 * changeX;
            int newY = y + 2 * changeY;
            if ( ( (newX >= 0) && (newX < N) ) && ( (newY >= 0) && (newY < M) ) )
            {
                first[newY][newX] = C;
            }
        }

        for (int i = 0; i < M; i++)
        {
            for (int j = 0; j < N; j++)
                cout << first[i][j];
            cout << endl;
        }
        cout << endl;
        cin >> M;
    }
    return 0;
}