#include #include #include #define DMAX 1020 using namespace std; int mat[DMAX][DMAX], X[DMAX][DMAX], Y[DMAX][DMAX]; int x[DMAX], y[DMAX]; int n, m, h; char c; class cmp { public: bool operator()(const pair& a, const pair& b) { int key, key2; if(a.second==1) key=x[a.first]; else key=y[a.first]; if(b.second==1) key2=x[b.first]; else key2=y[b.first]; return key>key2; } }; int main() { // freopen("in.txt", "r", stdin); cin>>n>>m>>h; for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) { cin>>c; if(c=='.') mat[i][j]=-1; else mat[i][j]=-2; } for(int i=1; i<=h; i++) for(int j=1; j<=m; j++) { cin>>c; if(c=='.') X[i][j]=0; else X[i][j]=1; } for(int i=1; i<=h; i++) for(int j=1; j<=n; j++) { cin>>c; if(c=='.') Y[i][j]=0; else Y[i][j]=1; } for(int i=1; i<=n; i++) for(int j=1; j<=h; j++) x[i]+=X[j][i]; for(int i=1; i<=m; i++) for(int j=1; j<=h; j++) y[i]+=Y[j][i]; priority_queue , vector >, cmp> p; for(int i=1;i<=n;i++) if(x[i]!=0) p.push(make_pair(i, 1)); for(int i=1;i<=m;i++) if(y[i]!=0) p.push(make_pair(i, 2)); while(!p.empty()) { int a; pair pi=p.top(); p.pop(); if(pi.second==1) { int s=pi.first; a=x[pi.first]; for(int i=1;i<=n;i++) if(mat[i][s]==-2) { mat[i][s]=a; } } else { int s=n-pi.first+1; a=y[pi.first]; for(int i=1;i<=m;i++) if(mat[s][i]==-2) { mat[s][i]=a; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) if(mat[i][j]==-1) cout<<'.'; else cout<