import math import sys import fractions sys.setrecursionlimit(2 ** 20) # DEBUG = True DEBUG = False if DEBUG: input = open('date.in', 'r') output = open('date.out', 'w') else: input = sys.stdin output = sys.stdout line = input.readline().strip().split() N = int(line[0]) M = int(line[1]) H = int(line[2]) top = [ '' for i in range(N) ] cols = [ '' for i in range(H) ] rows = [ '' for i in range(H) ] for i in range(N): top[i] = input.readline().strip() for i in range(H): cols[i] = input.readline().strip() for i in range(H): rows[i] = input.readline().strip() maxInRow = [ 0 for i in range(N) ] maxInCol = [ 0 for i in range(M) ] for j in range(M): h = H - 1 while h >= 0 and cols[h][j] == '#': h -= 1 maxInCol[j] = H - 1 - h for j in range(N): h = H - 1 while h >= 0 and rows[h][j] == '#': h -= 1 maxInRow[N - 1 - j] = H - 1 - h ans = [ [ '.' for j in range(M) ] for i in range(N) ] for i in range(N): for j in range(M): c = top[i][j] if top[i][j] == '#': c = min(maxInRow[i], maxInCol[j]) ans[i][j] = str(c) output.write('{}'.format(c)) output.write('\n') input.close() output.close()