#include <iostream>
#include <string>

using namespace std;


int R, C;
char CC = 0;
string M1[1001];
string M2[1001];

int x1, y1, x2, y2;

char getC(int x, int y){
    int X = x - x1;
    int Y = y - y1;
    if(X>=0 && Y>=0 && X<C && Y<R && M2[Y][X] == CC)return CC;
    char r = M1[y][x];
    return r == CC ? M2[y][x] : r;
}

int main(){
    ios::sync_with_stdio(false);
    while(true){
        string tmp;
        cin>>R>>C>>tmp;
        if(R==0) return 0;
        CC = tmp[1];
            
        getline(cin,M1[0]);
        for(int i=0; i<R; i++)
            getline(cin,M1[i]);
            
        getline(cin,M2[0]);
        for(int i=0; i<R; i++)
            getline(cin,M2[i]);
            
        
        bool found = false;
        for(y1=0; y1<R && !found; y1++)
            for(x1=0; x1<C && !found; x1++)
                if(M1[y1][x1] == CC)found = true;

        found = false;      
        for(y2=0; y2<R && !found; y2++)
            for(x2=0; x2<C && !found; x2++)
                if(M2[y2][x2] == CC)found = true;


        //cout << x1 << ' '<< y1 << endl;
        //cout << x2 << ' '<< y2 << endl;
        
        x1 = x2 - x1; y1 = y2 - y1;
        //cout << x1 << ' '<< y1 << endl;
        
        for(int y=0; y<R; y++){
            for(int x=0; x<C; x++)
                cout<<getC(x,y);
            cout<<endl;
        }
        cout<<endl;
    }
}