''' Created on Mar 12, 2015 @author: user ''' def init(l, n, m, done): for _ in range(n): l1 = [] for _ in range(m): l1.append(0) l.append(l1) done.append(False) if __name__ == '__main__': l = [] done = [] n, m, h = map(int, raw_input().split(' ')) init(l, n, m, done) for i in range(n): s = raw_input() for j in range(len(s)): if s[j] == '#': l[i][j] = 1 for k in range(h): s = raw_input() for j in range(len(s)): if s[j] == '#': for i in range(n): if l[i][j] == 1: l[i][j] = h-k for k in range(h): s = raw_input() for i in range(len(s)): if s[i] == '#': found = False for j in range(m): if not done[n-i-1]: if l[n-i-1][j] > h-k: l[n-i-1][j] = h-k if l[n-i-1][j] > 0: found = True if found: done[n-i-1] = True s = [] for i in range(n): s1 = '' for j in range(m): if l[i][j] == 0: s1 = s1 + '.' else: s1 = s1 + str(l[i][j]) s.append(s1) for i in range(n): print s[i]