#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    while(true)
    {
        int M,N;
        string tmpalfaChar;
        cin>>M>>N>>tmpalfaChar;
        if(M==0)
        {
            return 0;
        }
        char alfaChar=(char)tmpalfaChar[1];
        //cout<<":"<<tmpalfaChar<<":"<<endl;
        //cout<<"alfa char: "<<alfaChar<<endl;

        char ** image1= new char *[M];
        char ** image2= new char *[M];
        for (int i=0;i<M;i++)
        {
            image1[i]=new char [N];
            image2[i]=new char [N];
        }

        //Nacitani
        int i1firstM,i2firstM,i1firstN,i2firstN;
        bool i1firstFound=false;
        bool i2firstFound=false;
        for (int i=0;i<M;i++)
        {
            for(int j=0;j<N;j++)
            {
                cin>>image1[i][j];
                if (i1firstFound==false)
                {
                    if (image1[i][j]==alfaChar)
                    {
                        i1firstFound=true;
                        i1firstM=i;
                        i1firstN=j;
                    }
                }
            }
        }
        //cin>>tmpalfaChar;
        for (int i=0;i<M;i++)
        {
            for(int j=0;j<N;j++)
            {
                cin>>image2[i][j];
                if (i2firstFound==false)
                {
                    if (image2[i][j]==alfaChar)
                    {
                        i2firstFound=true;
                        i2firstM=i;
                        i2firstN=j;
                    }
                }
            }
        }

        int MPosunProRekonstrukci=2*(i2firstM-i1firstM);
        int NPosunProRekonstrukci=2*(i2firstN-i1firstN);
        //cout<<i1firstM<<i1firstN<<endl;
        //cout<<i2firstM<<i2firstN<<endl;
        //cout<<"MPosun "<<MPosunProRekonstrukci<<endl<<"NPosun "<<NPosunProRekonstrukci<<endl;
        //Rekonstrukce obrazku

        for (int i=0;i<M;i++)
        {
            for(int j=0;j<N;j++)
            {
                if (i-MPosunProRekonstrukci>=0 && i-MPosunProRekonstrukci<M && j-NPosunProRekonstrukci>=0 && j-NPosunProRekonstrukci<N)
                {
                    //Zkoumame falcona
                    if (image1[i-MPosunProRekonstrukci][j-NPosunProRekonstrukci]==alfaChar)
                    {
                        cout<<alfaChar;
                    }
                    else
                    {
                        if (image1[i][j]!=alfaChar)
                        {
                            cout<<image1[i][j];
                        }
                        else
                        {
                            cout<<image2[i][j];
                        }
                    }
                }
                else
                {
                    if (image1[i][j]!=alfaChar)
                    {
                        cout<<image1[i][j];
                    }
                    else
                    {
                        cout<<image2[i][j];
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;

        //cin>>tmpalfaChar;
        //cout<<"dokonceno nacitani"<<endl;

        //Vypis
        /*for (int i=0;i<M;i++)
        {
            for(int j=0;j<N;j++)
            {
                cout<<image1[i][j];
            }
            cout<<endl;
        }
        cout<<endl;

        for (int i=0;i<M;i++)
        {
            for(int j=0;j<N;j++)
            {
                cout<<image2[i][j];
            }
            cout<<endl;
        }*/
    }
    return 0;
}