#include //#include using namespace std; //ifstream f ("file.in"); const int NMAX = 1000 + 1, MMAX = 1000 + 1, HMAX = 9 + 1; int n, m, h; int maxim[MMAX], maxim2[MMAX]; char top[NMAX][MMAX]; int rez[NMAX][MMAX]; void citeste() { cin >> n >> m >> h; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> top[i][j]; } void rezolva() { char a; int x; for (int i = 1; i <= h; i++) for (int j = 1; j <= m; j++) { cin >> a; if (a == '#') maxim[j]++; } for (int i = 1; i <= m; i++) { if (!maxim[i]) continue; for (int k = 1; k <= n; k++) if (top[k][i] == '#') rez[k][i] = maxim[i]; } for (int i = 1; i <= h; i++) for (int j = n; j >= 1; j--) { cin >> a; if (a == '#') maxim2[j]++; } for (int i = 1; i <= n; i++) { if (maxim2[i] == 0) continue; for (int k = 1; k <= m; k++) if (top[i][k] == '#') rez[i][k] = min(rez[i][k], maxim2[i]); } } void scrie() { for (int i = 1; i <= n; i++, cout << '\n') for (int j = 1; j <= m; j++) { if (top[i][j] == '.') cout << '.'; else cout << rez[i][j]; } } int main() { citeste(); rezolva(); scrie(); }