#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i = a;i<n;i++)
#define ll long long

int main(){
    iostream::sync_with_stdio(false);
    cout<<fixed<<setprecision(9);
    
    int h, w;
    while(true){
    	cin >> h >> w;
    	if(!h) return 0;
    	string temps;
    	cin >> temps;
		char c = temps[1];
		
		string s[2][h];
		rep(frame,0,2) rep(i,0,h) cin >> s[frame][i];
		string bg[h];
		rep(i,0,h) {
			bg[i] = s[0][i];
			rep(j,0,w) if(s[1][i][j]!=c) bg[i][j] = s[1][i][j];
		}
		int my[2], mx[2];
		rep(f,0,2){
			my[f] = h;
			mx[f] = w;
			rep(i,0,h) rep(j,0,w) if(s[f][i][j]==c){
				my[f] = min(my[f], i);
				mx[f] = min(mx[f], j);
			}
		}
		
		rep(i,0,h) rep(j,0,w){
			if(s[1][i][j] == c){
				int ny = i + my[1] - my[0];
				int nx = j + mx[1] - mx[0];
				if((nx>=0)&&(ny>=0)&&(nx<w)&&(ny<h)){
					bg[ny][nx] = c;
				}
			}
		}
		rep(i,0,h) cout << bg[i] << endl; cout << endl;
    }
    return 0;
}