#include #include #include #include #include #include #include #include #include #include using namespace std; int N, M, H, lin[1009], col[1009]; char tot[1009][1009], sus[1009][1009], stanga[1009][1009]; int main() { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d %d\n", &N, &M, &H); for (int i=1; i<=N; i++) gets (tot[i] + 1); for (int i=1; i<=H; i++) gets (sus[i] + 1); for (int j=1; j<=M; j++) { for (int i=1; i<=H; i++) if (sus[i][j] == '#') { col[j] = H - i + 1; break; } } for (int i=1; i<=H; i++) gets (stanga[i] + 1); for (int j=1; j<=N; j++) { for (int i=1; i<=H; i++) if (stanga[i][j] == '#') { lin[N - j + 1] = H - i + 1; break; } } for (int i=1; i<=N; i++, printf ("\n")) for (int j=1; j<=M; j++) { int val = min (lin[i], col[j]); if (tot[i][j] == '#' && val == 0) printf ("1"); else if (tot[i][j] == '#') printf ("%d", val); else printf ("."); } return 0; }