#include using namespace std; #define NMAX 1007 char cod; int t[NMAX][NMAX],sol[NMAX][NMAX]; int c[NMAX],l[NMAX]; int N,M,H,i,j,found; int main() { cin>>N>>M>>H; for (i=1;i<=N;++i) for (j=1;j<=M;++j) { cin>>cod; if (cod=='#') t[i][j]=1; } for (i=1;i<=H;++i) for (j=1;j<=M;++j) { cin>>cod; if (cod=='#') c[j]=max(c[j],H-i+1); } for (i=1;i<=H;++i) for (j=1;j<=N;++j) { cin>>cod; if (cod=='#') l[N-j+1]=max(l[N-j+1],H-i+1); } for (i=1;i<=N;++i) { found=false; for (j=1;j<=M && !found;++j) { if (c[j]>=l[i] && t[i][j]) { sol[i][j]=l[i]; found=true; } } } for (j=1;j<=M;++j) { found=false; for (i=1;i<=N && !found;++i) { if (sol[i][j]) { found=true; continue; } if (l[i]>=c[j] && t[i][j]) { sol[i][j]=c[j]; found=true; } } } for (i=1;i<=N;++i,cout<<'\n') for (j=1;j<=M;++j) { if (!t[i][j]) { cout<<'.'; continue; } if (!sol[i][j]) sol[i][j]=1; cout<