Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.

He has a special interest to create difficult problems for others to solve. This time, with many $1 \times 1 \times 1$ toy bricks, he builds up a 3-dimensional object. We can describe this object with a $n \times m$ matrix, such that in each cell $(i,j)$, there are $h_{i,j}$ bricks standing on the top of each other.

However, Serval doesn't give you any $h_{i,j}$, and just give you the front view, left view, and the top view of this object, and he is now asking you to restore the object. Note that in the front view, there are $m$ columns, and in the $i$-th of them, the height is the maximum of $h_{1,i},h_{2,i},\dots,h_{n,i}$. It is similar for the left view, where there are $n$ columns. And in the top view, there is an $n \times m$ matrix $t_{i,j}$, where $t_{i,j}$ is $0$ or $1$. If $t_{i,j}$ equals $1$, that means $h_{i,j}>0$, otherwise, $h_{i,j}=0$.

However, Serval is very lonely because others are bored about his unsolvable problems before, and refused to solve this one, although this time he promises there will be at least one object satisfying all the views. As his best friend, can you have a try?


-----Input-----

The first line contains three positive space-separated integers $n, m, h$ ($1\leq n, m, h \leq 100$) — the length, width and height.

The second line contains $m$ non-negative space-separated integers $a_1,a_2,\dots,a_m$, where $a_i$ is the height in the $i$-th column from left to right of the front view ($0\leq a_i \leq h$).

The third line contains $n$ non-negative space-separated integers $b_1,b_2,\dots,b_n$ ($0\leq b_j \leq h$), where $b_j$ is the height in the $j$-th column from left to right of the left view.

Each of the following $n$ lines contains $m$ numbers, each is $0$ or $1$, representing the top view, where $j$-th number of $i$-th row is $1$ if $h_{i, j}>0$, and $0$ otherwise.

It is guaranteed that there is at least one structure satisfying the input.


-----Output-----

Output $n$ lines, each of them contains $m$ integers, the $j$-th number in the $i$-th line should be equal to the height in the corresponding position of the top view. If there are several objects satisfying the views, output any one of them.


-----Examples-----
Input
3 7 3
2 3 0 0 2 0 1
2 1 3
1 0 0 0 1 0 0
0 0 0 0 0 0 1
1 1 0 0 0 0 0

Output
1 0 0 0 2 0 0
0 0 0 0 0 0 1
2 3 0 0 0 0 0

Input
4 5 5
3 5 2 0 4
4 2 5 4
0 0 0 0 1
1 0 1 0 0
0 1 0 0 0
1 1 1 0 0

Output
0 0 0 0 4
1 0 2 0 0
0 5 0 0 0
3 4 1 0 0



-----Note-----

 [Image] 

The graph above illustrates the object in the first example.

 [Image] 

 [Image] 

The first graph illustrates the object in the example output for the second example, and the second graph shows the three-view drawing of it.

Difficulty: EASY

Solutions:
(n, m, h) = list(map(int, input().split()))
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = [list(map(int, input().split())) for i in range(0, n)]
for i in range(0, n):
	for j in range(0, m):
		if top[i][j]:
			top[i][j] = min(left[i], front[j])
		print(top[i][j], end=' ')
	print()


from sys import stdin, stdout
(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
side = list(map(int, input().split()))
top = [None] * n
for i in range(n):
	top[i] = list(map(int, input().split()))
	for j in range(m):
		if top[i][j] == 1:
			top[i][j] = min(front[j], side[i])
for i in range(n):
	for j in top[i]:
		print(j, end=' ')
	print('')


(n, m, h) = map(int, input().split())
am = list(map(int, input().split()))
bn = list(map(int, input().split()))
hij = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if hij[i][j]:
			hij[i][j] = min(am[j], bn[i])
		print(hij[i][j], end=' ')
	print()


(x, y, z) = map(int, input().split())
yy = list(map(int, input().split()))
xx = list(map(int, input().split()))
for i in range(x):
	ans = ''
	z = list(map(int, input().split()))
	for j in range(0, len(z)):
		if z[j]:
			ans = ans + str(min(yy[j], xx[i])) + ' '
		else:
			ans += '0 '
	print(ans)


(n, m, h) = map(int, input().split())
top = list(map(int, input().split()))
left = list(map(int, input().split()))
matrix = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			print(min(left[i], top[j]), end=' ')
		else:
			print(0, end=' ')
	print()


import sys

def main():
	(n, m, h) = map(int, input().split())
	(M, N) = (list(map(int, sys.stdin.readline().split())), list(map(int, sys.stdin.readline().split())))
	delta = [0] * n
	for i in range(n):
		delta[i] = list(map(int, sys.stdin.readline().split()))
	for i in range(n):
		for j in range(m):
			if delta[i][j] == 0:
				print(0, end=' ')
			else:
				print(min(N[i], M[j]), end=' ')
		print()
main()


a = list(map(int, input().split()))
m = list(map(int, input().split()))
n = list(map(int, input().split()))
l = []
for i in range(a[0]):
	l.append(list(map(int, input().split())))
for i in range(a[1]):
	for j in range(a[0]):
		if l[j][i] == 1:
			if m[i] <= n[j]:
				l[j][i] = m[i]
for i in range(a[0]):
	for j in range(a[1]):
		if l[i][j] == 1:
			if n[i] <= m[j]:
				l[i][j] = n[i]
		print(l[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split())
f = list(map(int, input().split()))
s = list(map(int, input().split()))
mat = []
for i in range(n):
	x = list(map(int, input().split()))
	mat.append(x)
for i in range(n):
	for j in range(m):
		if mat[i][j] != 0:
			mat[i][j] = min(f[j], s[i])
for i in range(n):
	for j in range(m):
		print(str(mat[i][j]), sep=' ', end=' ')
	print()


(n, m, h) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
h = [[] for i in range(n)]
for i in range(n):
	h[i] = [int(i) for i in input().split()]
	for j in range(m):
		if h[i][j] > 0:
			h[i][j] = a[j]
		if h[i][j] > b[i]:
			h[i][j] = b[i]
for i in range(n):
	for j in range(m):
		print(h[i][j], end=' ')
	print()


(l, f, h) = tuple(map(int, input().split()))
data = []
temp = []
for j in range(f):
	temp.append([1] * h)
for i in range(l):
	data.append(temp[:])
fv = [int(i) for i in input().split()]
badf = set()
index = 0
for j in fv:
	index += 1
	for i in range(j + 1, h + 1):
		badf.add((index, i))
lv = [int(i) for i in input().split()]
badl = set()
index = 0
for j in lv:
	index += 1
	for i in range(j + 1, h + 1):
		badl.add((index, i))
for i in range(1, l + 1):
	row = input().split()
	for j in range(1, f + 1):
		if row[j - 1] == '1':
			s = 0
			for k in range(1, h + 1):
				if (i, k) not in badl and (j, k) not in badf:
					s += 1
			print(s, end=' ')
		else:
			print('0', end=' ')
	print()


(n, m, h) = input().split()
n = int(n)
m = int(m)
h = int(h)
fv = input().split()
lv = input().split()
tv = []
for i in range(n):
	tv.append(input().split())
	for j in range(m):
		if tv[i][j] == '1':
			tv[i][j] = min(int(fv[j]), int(lv[i]))
		else:
			tv[i][j] = 0
for i in range(n):
	s = ''
	for j in range(m):
		s = s + str(tv[i][j]) + ' '
	print(s)


(n, h, m) = map(int, input().split())
l = list(map(int, input().split()))
l2 = list(map(int, input().split()))
k = []
for i in range(n):
	e = list(map(int, input().split()))
	k.append(e)
for i in range(n):
	for j in range(h):
		if k[i][j] == 1:
			k[i][j] = min(l[j], l2[i])
			print(k[i][j], end=' ')
		else:
			print(k[i][j], end=' ')
	print()


import sys
(n, m, h) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
hrr = []
for i in range(n):
	hrr.append(list(map(int, input().split())))
arr = hrr
for i in range(n):
	for j in range(m):
		if hrr[i][j] > 0:
			arr[i][j] = min(a[j], b[i])
for i in range(n):
	for j in range(m):
		print(arr[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
table = [list(map(int, input().split())) for i in range(n)]
answer = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if table[i][j] == 1:
			answer[i][j] = min(a[j], b[i])
for i in range(n):
	for j in range(m):
		print(answer[i][j], end=' ')
	print()


import math
import sys
from collections import *
import itertools

def cint():
	return list(map(int, sys.stdin.readline().strip().split()))

def cstr():
	return list(map(str, input().split(' ')))

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def solve(t):
	(n, m, h) = cint()
	front = cint()
	left = cint()
	mat = []
	for i in range(n):
		mat.append(cint())
	for i in range(n):
		for j in range(m):
			if mat[i][j] != 0:
				mat[i][j] = min(front[j], left[i])
	for i in range(n):
		for j in range(m):
			print(mat[i][j], end=' ')
		print('')
t = 1
for i in range(1, t + 1):
	solve(i)


(n, m, h) = map(int, input().split())
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
h = []
for i in range(n):
	h.append([int(x) for x in input().split()])
o = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		o[i][j] = h[i][j] * min(left[i], front[j])
		print(o[i][j], end=' ')
	print()


import sys

def get_line():
	return list(map(int, sys.stdin.readline().strip().split()))

def in1():
	return int(input())
(n, m, k) = get_line()
f = get_line()
left = get_line()
c = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	b = get_line()
	for j in range(m):
		if b[j] == 1:
			c[i][j] = min(f[j], left[i])
for i in range(n):
	for j in range(m):
		print(c[i][j], end=' ')
	print()


import sys, os, re, datetime
from collections import *
from bisect import *

def mat(v, *dims):

	def submat(i):
		if i == len(dims) - 1:
			return [v for _ in range(dims[-1])]
		return [submat(i + 1) for _ in range(dims[i])]
	return submat(0)
__cin__ = None

def cin():
	global __cin__
	if __cin__ is None:
		__cin__ = iter(input().split(' '))
	try:
		return next(__cin__)
	except StopIteration:
		__cin__ = iter(input().split(' '))
		return next(__cin__)

def iarr(n):
	return [int(cin()) for _ in range(n)]

def farr(n):
	return [float(cin()) for _ in range(n)]

def sarr(n):
	return [cin() for _ in range(n)]

def carr(n):
	return input()

def imat(n, m):
	return [iarr(m) for _ in range(n)]

def fmat(n, m):
	return [farr(m) for _ in range(n)]

def smat(n, m):
	return [sarr(m) for _ in range(n)]

def cmat(n, m):
	return [input() for _ in range(n)]
n = int(cin())
m = int(cin())
h = int(cin())
mv = iarr(m)
nv = iarr(n)
tv = imat(n, m)
ans = mat(0, n, m)
for i in range(n):
	for j in range(m):
		if tv[i][j] == 1:
			ans[i][j] = nv[i]
for j in range(m):
	for i in range(n):
		if tv[i][j] == 1:
			ans[i][j] = min(ans[i][j], mv[j])
for _r in ans:
	for v in _r:
		sys.stdout.write(str(v) + ' ')
	print()


import sys
(n, m, h) = map(int, input().split())
aa = [int(x) for x in input().split()]
bb = [int(x) for x in input().split()]
hh = [[0] * m for _ in range(n)]
ans = [[0] * m for _ in range(n)]
for i in range(n):
	hh[i] = [int(x) for x in input().split()]
for i in range(n):
	for j in range(m):
		if hh[i][j] == 1:
			ans[i][j] = min(aa[j], bb[i])
		print(ans[i][j], end=' ')
	print()


import math

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
mod = 1000000000.0
(n, m, h) = mi()
a = li()
b = li()
for i in range(n):
	h = li()
	for j in range(m):
		x = min(b[i], a[j])
		if h[j] == 1:
			print(x, end=' ')
		else:
			print('0', end=' ')
	print()


(n, m, h) = map(int, input().split())
f = list(map(int, input().split()))
l = list(map(int, input().split()))
tab = []
for i in range(n):
	tab.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if tab[i][j] != 0:
			tab[i][j] = min(l[i], f[j])
for i in range(n):
	for j in range(m):
		print(tab[i][j], end=' ')
	print()


(Dx, Dy, Dz) = map(int, input().split(' '))
X = list(map(int, input().split(' ')))
Y = list(map(int, input().split(' ')))
mat = []
for _ in range(Dx):
	mat.append(list(map(int, input().split(' '))))
for i in range(len(mat)):
	for j in range(len(mat[0])):
		if mat[i][j] == 1:
			print(min(X[j], Y[i]), end=' ')
		else:
			print('0', end=' ')
	print()


(n, m, h) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [[int(i) for i in input().split()] for j in range(n)]
for i in range(n):
	target = b[i]
	for j in range(m):
		if c[i][j] == 0:
			continue
		if a[j] < target:
			continue
		c[i][j] = target
for j in range(m):
	target = a[j]
	for i in range(n):
		if c[i][j] == 0:
			continue
		if b[i] < target:
			continue
		c[i][j] = target
for row in c:
	for col in row:
		print(col, end=' ')
	print()


(n, m, h) = map(int, input().split())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
l = []
for i in range(n):
	l.append([*map(int, input().split())])
for i in range(n):
	for j in range(m):
		l[i][j] *= min(a[j], b[i])
		print(l[i][j], end=' ')
	print()


import sys
input = sys.stdin.readline
(N, M, H) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
state = [list(map(int, input().split())) for _ in range(N)]
ans = [[0 for _ in range(M)] for _ in range(N)]
for i in range(N):
	for j in range(M):
		if state[i][j] == 1:
			ans[i][j] = min(A[j], B[i])
for i in range(N):
	for j in range(M):
		print(ans[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split(' '))
fview = list(map(int, input().split(' ')))
lview = list(map(int, input().split(' ')))
grid = []
for x in range(n):
	grid.append(list(map(int, input().split(' '))))
for x in range(n):
	for y in range(m):
		if grid[x][y] == 1:
			print(min(lview[x], fview[y]), end=' ')
		else:
			print('0 ', end='')
	print('')


(n, m, h) = tuple(map(int, input().split(' ')))
heights_front = list(map(int, input().split(' ')))
heights_left = list(map(int, input().split(' ')))
heights_top = [list(map(int, input().split(' '))) for i in range(n)]
for i in range(n):
	for j in range(m):
		if heights_top[i][j] > 0:
			heights_top[i][j] = min(heights_front[j], heights_left[i])
		print(heights_top[i][j], end=' ')
	print()


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR, insort as INSORT
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write
L = list
M = map

def player1():
	print('')

def player2():
	print('')

def yes():
	PRINT('YES\n')

def no():
	PRINT('NO\n')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def checkPath(source, destination, g):
	visited = [0] * 101
	q = Q()
	q.append(source)
	visited[source] = 1
	while q:
		node = q.popleft()
		if node == destination:
			return 1
		for v in g[node]:
			if not visited[v]:
				q.append(v)
				visited[v] = 1
	return 0

def main():
	(n, m, h) = M(int, INPUT().split())
	col = L(M(int, INPUT().split()))
	row = L(M(int, INPUT().split()))
	a = []
	for i in range(n):
		a.append(L(M(int, INPUT().split())))
	ans = [[0 for j in range(m)] for j in range(n)]
	for (j, i) in P(range(m), range(n)):
		if a[i][j] == 1:
			ans[i][j] = col[j]
	for (i, j) in P(range(n), range(m)):
		if a[i][j] == 1:
			if row[i] <= ans[i][j]:
				ans[i][j] = row[i]
	for i in range(n):
		for j in range(m):
			PRINT('%d ' % ans[i][j])
		PRINT('\n')
main()


(n, m, h) = map(int, input().split())
arr = [int(x) for x in input().split()]
brr = [int(x) for x in input().split()]
top = []
for _ in range(n):
	top.append([int(x) for x in input().split()])
for i in range(n):
	for j in range(m):
		if top[i][j]:
			top[i][j] = min(brr[i], arr[j])
for i in range(n):
	for j in range(m):
		print(top[i][j], end=' ')
	print()


(n, m, h) = map(int, input().strip().split())
fv = list(map(int, input().strip().split()))
lv = list(map(int, input().strip().split()))
tv = []
for i in range(n):
	temp = list(map(int, input().strip().split()))
	tv.append(temp)
for i in range(n):
	for j in range(m):
		if tv[i][j] != 0:
			tv[i][j] = min(fv[j], lv[i])
for i in range(n):
	for j in range(m):
		print(tv[i][j], end=' ')
	print()


(N, M, H) = map(int, input().split())
FV = list(map(int, input().split()))
LV = list(map(int, input().split()))
TV = []
for n in range(N):
	row = list(map(int, input().split()))
	TV.append(row)
for r in range(N):
	for c in range(M):
		if TV[r][c] == 1:
			TV[r][c] = min(FV[c], LV[r])
for t in TV:
	for s in t:
		print(s, end=' ')
	print()


(n, m, h) = map(int, input().split())
front = [int(i) for i in input().split()]
left = [int(i) for i in input().split()]
data = [[int(i) for i in input().split()] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if data[i][j] != 0:
			print(min(left[i], front[j]), end=' ')
		else:
			print(0, end=' ')
	print()


arr = [int(x) for x in input().split()]
n = arr[0]
m = arr[1]
h = arr[2]
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
res = []
aux = []
for i in range(n):
	temp = [int(x) for x in input().split()]
	for k in range(len(temp)):
		if temp[k] == 0:
			aux.append(0)
		else:
			aux.append(min(left[i], front[k]))
	res.append(aux)
	aux = []
for i in res:
	for k in i:
		print(k, end=' ')
	print()


(n, m, h) = [int(x) for x in input().split()]
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
up = []
outputMatrix = [[0 for x in range(m)] for y in range(n)]
for i in range(n):
	up += [[int(x) for x in input().split()]]
for i in range(n):
	for j in range(m):
		if up[i][j] == 1:
			outputMatrix[i][j] = min(front[j], left[i])
for i in range(n):
	for j in range(m):
		print(outputMatrix[i][j], end=' ')
	print()


(n, m, h) = list(map(int, input().split()))
ans = [[0] * m for i in range(n)]
front = list(map(int, input().split()))
lef = list(map(int, input().split()))
up = [0] * n
for i in range(n):
	up[i] = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		ans[i][j] = h
for i in range(n):
	for j in range(m):
		ans[i][j] = front[j]
for i in range(n):
	for j in range(m):
		ans[i][j] = min(ans[i][j], lef[i])
for i in range(n):
	for j in range(m):
		if not up[i][j]:
			ans[i][j] = 0
for i in range(n):
	for j in range(m):
		print(ans[i][j], end=' ')
	print()


(n, m, hi) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
h = [list(map(int, input().split())) for i in range(n)]
vals = x + y
vals.sort()
ans = [[0 for i in range(m)] for _ in range(n)]
for v in vals:
	for j in range(m):
		if x[j] == v:
			for i in range(n):
				if h[i][j] == 1 and ans[i][j] == 0:
					ans[i][j] = v
	for i in range(n):
		if y[i] == v:
			for j in range(m):
				if h[i][j] == 1 and ans[i][j] == 0:
					ans[i][j] = v
for i in range(n):
	for j in range(m):
		print(ans[i][j], end=' ')
	print('')


def convert(string):
	return string.split(sep=None, maxsplit=-1)

def toint(lst):
	result = []
	for i in lst:
		result.append(int(i))
	return result

def printeach(lst):
	for i in lst:
		print(i, end=' ')

def printbox(m):
	for i in m:
		printeach(i)
		print('')
nmh = toint(convert(input()))
(n, m, h) = (nmh[0], nmh[1], nmh[2])
row = toint(convert(input()))
column = toint(convert(input()))
matrix = []
for i in range(n):
	matrix.append(toint(convert(input())))
for i in range(n):
	matrix[i] = list(map(lambda x: x * column[i], matrix[i]))
for i in range(m):

	def f(x):
		if x[i] > row[i]:
			x[i] = row[i]
		return x
	matrix = list(map(f, matrix))
printbox(matrix)


t = input()
t = t.split()
for i in range(len(t)):
	t[i] = int(t[i])
(n, m, k) = (t[0], t[1], t[2])
n1 = n
x = []
a = input()
a = a.split()
for i in range(len(a)):
	a[i] = int(a[i])
b = input()
b = b.split()
for i in range(len(b)):
	b[i] = int(b[i])
while n1 != 0:
	q = input().split()
	for i in range(len(q)):
		q[i] = int(q[i])
	x.append(q)
	n1 -= 1
for i in range(len(x)):
	for j in range(len(x[i])):
		if x[i][j]:
			x[i][j] = min(a[j], b[i])
		print(x[i][j], end=' ')
	print()


from math import sqrt, ceil, floor
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
import bisect
(n, m, h) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
fig = []
for i in range(n):
	fig.append(list(map(int, stdin.readline().split())))
ans = [[0 for x in range(m)] for y in range(n)]
for i in range(n):
	for j in range(m):
		if fig[i][j] == 1:
			print(min(a[j], b[i]), end=' ')
		else:
			print(0, end=' ')
	print()


(l, b, h) = map(int, input().split())
L = list(map(int, input().split()))
B = list(map(int, input().split()))
H = []
for _ in range(l):
	H.append(list(map(int, input().split())))
for i in range(l):
	for j in range(b):
		if H[i][j] == 1:
			H[i][j] = min(L[j], B[i])
for i in H:
	for j in i:
		print(j, end=' ')
	print('')


(a, b, c) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(a)]
for i in range(a):
	for j in range(b):
		print(min(A[j], B[i]) if C[i][j] else 0, end=' ')
	print()


(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = []
for i in range(n):
	top.append(list(map(int, input().split())))
res = top
for i in range(n):
	for j in range(m):
		if res[i][j] == 1:
			res[i][j] = min(left[i], front[j])
for i in range(n):
	for j in range(m):
		print(res[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split())
table = []
front = list(map(int, input().split()))
left = list(map(int, input().split()))
for i in range(n):
	line = list(map(int, input().split()))
	table.append(line)
for i in range(n):
	for j in range(m):
		if table[i][j] == 1:
			table[i][j] = min(front[j], left[i])
		print(table[i][j], end=' ')
	print()


def solve(n, m, h, front, left, top):
	for i in range(n):
		for j in range(m):
			if top[i][j] == 1:
				top[i][j] = min(left[i], front[j])
(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = []
for i in range(n):
	row = list(map(int, input().split()))
	top.append(row)
solve(n, m, h, front, left, top)
for i in range(n):
	for j in range(m):
		print(top[i][j], end=' ')
	print('')


def mp():
	return map(int, input().split())
(n, m, h) = mp()
a = list(mp())
b = list(mp())
f = [list(mp()) for i in range(n)]
for i in range(m):
	for j in range(n):
		f[j][i] *= min(a[i], b[j])
for i in range(n):
	for j in range(m):
		print(f[i][j], end=' ')
	print()


import sys
import functools
import itertools
import os
import math

def redirect_input_from_file():
	read_f = open('input.txt', 'r').readlines()

	def read_ff(prompt=''):
		return read_f.pop(0).strip()
	return read_ff

def redirect_output_to_file():
	write_f = open('output.txt', 'w')

	def write_ff(*args, sep=' ', end='\n', stop=False):
		if stop:
			write_f.close()
		else:
			print(*args, sep=sep, end=end, file=write_f)
	return write_ff

def memoize(function):
	memo = {}

	@functools.wraps(function)
	def f(*args):
		parsed_args = args
		parsed_args = []
		for arg in args:
			if type(arg) is list or type(arg) is set:
				arg = tuple(sorted(arg))
			parsed_args.append(arg)
		parsed_args = tuple(parsed_args)
		if parsed_args not in memo:
			memo[parsed_args] = function(*args)
			if not len(memo) & 32767:
				print('memoization limit exceeded({}) for function {}'.format(len(memo), function.__name__), file=sys.stderr)
		return memo[parsed_args]
	f.memo = memo
	return f

def input_one(f=int):
	return f(input().strip())

def input_row(f=int):
	return list(map(f, input_one(str).split()))

def input_column(n, f=int):
	return [input_one(f) for _ in range(n)]

def input_grid(n, f=int):
	return [input_row(f) for _ in range(n)]

def testcases():
	return range(1, int(input().strip()) + 1)

def create_grid(n, m, default):
	return [[default] * m for _ in range(n)]

def solve():
	(n, m, h) = input_row()
	row_view = input_row()
	col_view = input_row()
	top_view = input_grid(n)
	grid = create_grid(n, m, 0)
	for i in range(n):
		for j in range(m):
			grid[i][j] = col_view[i]
	for i in range(n):
		for j in range(m):
			grid[i][j] = min(row_view[j], grid[i][j])
	for i in range(n):
		for j in range(m):
			grid[i][j] *= top_view[i][j]
	for i in grid:
		for j in i:
			print(j, end=' ')
		print()
solve()


def i():
	return list(map(int, input().split(' ')))
(n, m, h) = i()
front = i()
left = i()
top = []
for x in range(n):
	top.append(i())
bricks = [[h for x in range(m)] for y in range(n)]
for c in range(n):
	for r in range(m):
		bricks[c][r] = min(h, left[c], front[r]) * top[c][r]
for i in range(n):
	a = ''
	for j in range(m):
		a += str(bricks[i][j]) + ' '
	a.strip(' ')
	print(a)


(n, m, h) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
for i in range(0, n):
	for (j, x) in enumerate(map(int, input().split(' '))):
		if x == 0:
			print(0, end=' ')
		else:
			print(min(a[j], b[i]), end=' ')
	print()


(n, m, h) = map(int, input().split())
lis = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	p = list(map(int, input().split()))
	lis.append(p)
for i in range(n):
	for j in range(m):
		if lis[i][j] == 1:
			lis[i][j] = min(b[i], a[j])
for i in range(n):
	for j in range(m):
		print(lis[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split())
cl = list(map(int, input().split()))
rw = list(map(int, input().split()))
l = []
for i in range(len(rw)):
	l.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if l[i][j] != 0:
			l[i][j] = min(rw[i], cl[j])
for i in range(n):
	for j in range(m):
		print(l[i][j], end=' ')
	print()


(n, m, h) = tuple(map(int, input().split()))
col = list(map(int, input().split()))
row = list(map(int, input().split()))
H = [[0] * m] * n
for i in range(n):
	l = list(map(int, input().split()))
	for j in range(m):
		print(l[j] * min(col[j], row[i]), end=' ')
		H[i][j] = l[j]
	print()


import sys
(n, m, h) = map(int, sys.stdin.readline().split())
x_y = [[0] * m for _ in range(n)]
a_list = list(map(int, sys.stdin.readline().split()))
b_list = list(map(int, sys.stdin.readline().split()))
for i in range(n):
	c_list = list(map(int, sys.stdin.readline().split()))
	for j in range(m):
		if c_list[j] == 1:
			X = a_list[j]
			Y = b_list[i]
			C = int(min(X, Y))
			x_y[i][j] = C
for p in range(n):
	for q in range(m):
		print(x_y[p][q], end=' ')
	print()


(n, m, h) = map(int, input().split())
t = []
res = [[0] * m for i in range(n)]
f = list(map(int, input().split()))
l = list(map(int, input().split()))
for _ in range(n):
	temp = list(map(int, input().split()))
	t.append(temp)
for i in range(n):
	for j in range(m):
		res[i][j] = t[i][j] * min(l[i], f[j])
for i in range(n):
	for j in range(m):
		print(res[i][j], end=' ')
	print('')


def main():
	(n, m, h) = map(int, input().split())
	front = list(map(int, input().split()))
	left = list(map(int, input().split()))
	top = []
	grid = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		row = list(map(int, input().split()))
		top.append(row)
	for i in range(n):
		max_allowed = left[i]
		for j in range(m):
			if top[i][j] == 1:
				if front[j] <= max_allowed:
					grid[i][j] = front[j]
				else:
					grid[i][j] = min(front[j], max_allowed)
			else:
				grid[i][j] = 0
	for i in range(n):
		for j in range(m):
			print(grid[i][j], end=' ')
		print()
main()


(a, b, c) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
s = []
for i in range(a):
	s += [list(map(int, input().split()))]
for i in range(a):
	for j in range(b):
		if s[i][j] == 1:
			s[i][j] = min(l[j], l1[i])
for i in range(a):
	for j in range(b):
		print(s[i][j], end=' ')
	print()


(a, b, c) = map(int, input().split())
z = list(map(int, input().split()))
z1 = list(map(int, input().split()))
z2 = []
r = [list(map(int, input().split())) for _ in ' ' * a]
for i in range(a):
	k = [0] * b
	for j in range(b):
		if r[i][j] == 1:
			print(min(z1[i], z[j]), end=' ')
		else:
			print(0, end=' ')
	print()


(N, M, H) = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
items = []
for i in range(N):
	items.append(tuple(map(int, input().split())))
ans = []
for i in range(N):
	tmp = []
	for j in range(M):
		now = items[i][j]
		if now == 0:
			tmp.append(0)
		else:
			a = a_list[j]
			b = b_list[i]
			tmp.append(min(a, b))
	ans.append(tmp)
for a in ans:
	for t in a:
		print(t, end=' ')
	print()


(n, m, h) = map(int, input().split())
mcolunas = list(map(int, input().split()))
nlinhas = list(map(int, input().split()))
tmatriz = []
for linha in range(n):
	tmatriz.append(list(map(int, input().split())))
for linha in range(n):
	for coluna in range(m):
		celula = tmatriz[linha][coluna]
		if celula:
			maior_linha = nlinhas[linha]
			maior_coluna = mcolunas[coluna]
			tmatriz[linha][coluna] = min([maior_linha, maior_coluna])
for linha in tmatriz:
	s = ''
	for ele in linha:
		s += '%i ' % ele
	print(s[:len(s)])


nmh = list(map(int, input().split()))
n = nmh[0]
m = nmh[1]
h = nmh[2]
result = [[0 for _ in range(m)] for _ in range(n)]
front = list(map(int, input().split()))
left = list(map(int, input().split()))
for i in range(n):
	row = input().split()
	for j in range(len(row)):
		if row[j] == '0':
			print('0', end=' ')
			continue
		result[i][j] = min(front[j], left[i])
		print(result[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
li = []
for i in range(n):
	temp = [int(x) for x in input().split()]
	li.append(temp)
for i in range(n):
	for j in range(m):
		if li[i][j] == 1:
			li[i][j] = min(b[i], a[j])
for i in range(n):
	for j in range(m):
		print(li[i][j], end=' ')
	print()


for _ in range(1):
	(n, m, h) = map(int, input().split())
	front = list(map(int, input().split()))
	left = list(map(int, input().split()))
	top = []
	for i in range(n):
		c = list(map(int, input().split()))
		top.append(c.copy())
	for i in range(n):
		for j in range(m):
			ft = front[j]
			lt = left[i]
			if top[i][j] != 0:
				top[i][j] = min(lt, ft)
	for i in range(n):
		for j in range(m):
			print(top[i][j], end=' ')
		print()


(a, b, c) = map(int, input().split())
v = list(map(int, input().split()))
arr = [list(v) for j in range(a)]
v = list(map(int, input().split()))
for i in range(a):
	d = list(map(int, input().split()))
	for j in range(b):
		if arr[i][j] > v[i]:
			arr[i][j] = v[i]
		if d[j] == 0:
			arr[i][j] = 0
		print(arr[i][j], end=' ')
	print()


import math
(n, m, h) = map(int, input().split())
b = list(map(int, input().split()))
a = list(map(int, input().split()))
c = []
dd = [0] * m
res = []
res1 = []
for i in range(n):
	temp = list(map(int, input().split()))
	c.append(temp)
	res.append(dd)
	res1.append([])
for i in range(n):
	for j in range(m):
		res[i][j] = b[j]
for i in range(n):
	for j in range(m):
		if c[i][j] == 1:
			res1[i].append(min(res[i][j], a[i]))
		else:
			res1[i].append(0)
for i in range(n):
	for j in range(m):
		print(res1[i][j], end=' ')
	print()


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if ans[i][j] == 1:
			ans[i][j] = min(a[j], b[i])
		print(ans[i][j], end=' ')
	print(sep='/n')


(n, m, h) = tuple(map(int, input().split()))
col = list(map(int, input().split()))
row = list(map(int, input().split()))
hei = [[0] * m] * n
for i in range(n):
	li = list(map(int, input().split()))
	for j in range(m):
		print(li[j] * min(col[j], row[i]), end=' ')
		hei[i][j] = li[j]
	print()