#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define dbg(x) (cout<<#x<<" = "<<(x)<<'\n') #ifdef HOME const string inputFile = "input.txt"; const string outputFile = "output.txt"; #else const string problemName = ""; const string inputFile = problemName + ".in"; const string outputFile = problemName + ".out"; #endif typedef long long int lld; typedef pair PII; typedef pair PIL; typedef pair PLI; typedef pair PLL; const int INF = (1LL << 31) - 1; const lld LINF = (1LL << 62) - 1; const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int MOD = (int)(1e9) + 7; const int NMAX = 1000 + 5; const int MMAX = 100000 + 5; const int KMAX = 100000 + 5; const int PMAX = 100000 + 5; const int LMAX = 100000 + 5; const int VMAX = 100000 + 5; int N, M, H; int P[NMAX]; int Q[NMAX]; char A[NMAX][NMAX]; char B[NMAX][NMAX]; char C[NMAX][NMAX]; vector HP[20], HQ[20]; int main() { int i, j, h; #ifndef ONLINE_JUDGE freopen(inputFile.c_str(), "r", stdin); freopen(outputFile.c_str(), "w", stdout); #endif scanf("%d%d%d", &N, &M, &H); for(i = 1; i <= N; i++) scanf("%s", A[i] + 1); for(i = 1; i <= H; i++) scanf("%s", B[i] + 1); for(i = 1; i <= H; i++) scanf("%s", C[i] + 1); for(j = 1; j <= M; j++) { h = 0; for(i = H; i >= 1; i--) if(B[i][j] == '#') h++; P[j] = h; HP[h].push_back(j); } for(j = 1; j <= N; j++) { h = 0; for(i = H; i >= 1; i--) if(C[i][j] == '#') h++; Q[N - j + 1] = h; HQ[h].push_back(N - j + 1); } for(h = 1; h <= H; h++) { for(auto j : HP[h]) for(i = 1; i <= N; i++) if(A[i][j] == '#') A[i][j] = h + '0'; for(auto i : HQ[h]) for(j = 1; j <= M; j++) if(A[i][j] == '#') A[i][j] = h + '0'; } for(i = 1; i <= N; i++) printf("%s\n", A[i] + 1); return 0; }