#include #include using namespace std; int n, m, res[1001][1001], col[1001], lin[1001], h; char ch; struct sir { int val, tip, ind; }; sir v[2001], temp; bool comp(const sir &a, const sir &b) { return a.val>n>>m>>h; in.get(); for(int i=1; i<=n; ++i){ for(int j=1; j<=m; ++j){ ch=in.get(); if(ch=='#') res[i][j]=-1; } in.get(); } for(int i=1; i<=h; ++i){ for(int j=1; j<=m; ++j){ ch=in.get(); if(ch=='#') col[j]++; } in.get(); } for(int i=1; i<=h; ++i){ for(int j=1; j<=n; ++j){ ch=in.get(); if(ch=='#') lin[n+1-j]++; } in.get(); } for(int i=1; i<=m; ++i){ temp.tip=1; temp.val=col[i]; temp.ind=i; v[i]=temp; } for(int i=1; i<=n; ++i){ temp.tip=2; temp.val=lin[i]; temp.ind=i; v[m+i]=temp; } sort(v+1, v+n+m+1, comp); for(int i=1; i<=m+n; ++i){ temp=v[i]; if(temp.tip==1){ for(int j=1; j<=n; ++j){ if(res[j][temp.ind]<0){ res[j][temp.ind]=temp.val; } } } if(temp.tip==2){ for(int j=1; j<=m; ++j){ if(res[temp.ind][j]<0){ res[temp.ind][j]=temp.val; } } } } for(int i=1; i<=n; ++i){ for(int j=1; j<=m; ++j){ if(res[i][j]==0) out<<"."; else out<