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.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Constructive algorithms


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 collections import defaultdict
(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
front = defaultdict(int)
for (i, x) in enumerate(a):
	front[i] = x
left = defaultdict(int)
for (i, x) in enumerate(b):
	left[i] = x
out = [[0 for x in range(m)] for y in range(n)]
for i in range(n):
	x = list(map(int, input().split()))
	for (j, b) in enumerate(x):
		if b:
			out[i][j] = min(left[i], front[j])
for x in out:
	print(*x)


(n, m, h) = map(int, input().split())
f = list(map(int, input().split()))
s = list(map(int, input().split()))
t = []
for _ in range(n):
	t.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if t[i][j] == 1:
			t[i][j] = min(f[j], s[i])
[print(*t[i]) for i in range(n)]


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()


import sys
input = sys.stdin.readline
(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
grid = []
for i in range(n):
	grid.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if grid[i][j] == 1:
			grid[i][j] = min(front[j], left[i])
for row in grid:
	print(' '.join([str(x) for x in row]))


(n, m, h) = [int(k) for k in input().split(' ')]
cols = [int(k) for k in input().split(' ')]
rows = [int(k) for k in input().split(' ')]
mat = []
res = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	mat += [[int(k) for k in input().split(' ')]]
for i in range(n):
	for j in range(m):
		res[i][j] = str(mat[i][j] * min(cols[j], rows[i]))
	print(' '.join(res[i]))


(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)


(l, w, h) = map(int, input().split())
front = list(map(int, input().split()))
side = list(map(int, input().split()))
top = [list(map(int, input().split())) for i in range(l)]
row_mat = []
for rowh in side:
	row_mat.append([rowh] * w)
col_mat = []
for i in range(l):
	col_mat.append(front)
assert len(row_mat) == len(col_mat), 'Matrices were set up incorrectly'
assert len(row_mat[0]) == len(col_mat[0]), 'Matrices were set up incorrectly, column sizes do not match ({}, {})'.format(len(row_mat[0]), len(col_mat[0]))
intersection_matrix = []
for i in range(len(row_mat)):
	row = []
	for j in range(len(row_mat[0])):
		row.append(min(row_mat[i][j], col_mat[i][j]))
	intersection_matrix.append(row)
h_matrix = []
for i in range(len(intersection_matrix)):
	row = []
	for j in range(len(intersection_matrix[0])):
		row.append(intersection_matrix[i][j] if top[i][j] != 0 else 0)
	h_matrix.append(row)
for r in h_matrix:
	print(' '.join(map(str, r)))


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def __next__(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(next(self))

	def cal(self, s):
		if len(s) == 1:
			return s[0]
		if s[0] == 0:
			return self.cal(s[1:])
		v = 1
		for c in s:
			v *= c
		return v

	def solve(self):
		n = self.next_int()
		m = self.next_int()
		h = self.next_int()
		f = [self.next_int() for _ in range(0, m)]
		l = [self.next_int() for _ in range(0, n)]
		for i in range(0, n):
			rs = []
			for j in range(0, m):
				if self.next_int() == 0:
					rs.append(0)
				else:
					rs.append(min(f[j], l[i]))
			print(' '.join([str(x) for x in rs]))

def __starting_point():
	Main().solve()
__starting_point()


(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()


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq

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

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, m, h) = listIn()
a = listIn()
b = listIn()
mtx = []
for i in range(n):
	temp = [0] * m
	c = listIn()
	for j in range(m):
		if c[j] == 1:
			temp[j] = min(b[i], a[j])
	print(*temp)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m, h) = f()
cl = il()
rl = il()
for i in range(n):
	l = il()
	for j in range(m):
		if l[j] == 1:
			l[j] = min(rl[i], cl[j])
	print(*l)


(n, m, h) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
grid = [[int(x) for x in input().split(' ')] for row in range(n)]
ans = grid.copy()
for i in range(m):
	for j in range(n):
		if grid[j][i] == 0:
			ans[j][i] == 0
		else:
			ans[j][i] = min(a[i], b[j])
for row in ans:
	print(*row)


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()


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, h) = mapin()
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = []
for i in range(n):
	c = [int(x) for x in input().split()]
	for j in range(m):
		if c[j]:
			c[j] = min(a[j], b[i])
	d.append(c)
for i in d:
	print(*i)


I = lambda : map(int, input().split())
(n, *_) = I()
A = list(I())
B = list(I())
for j in range(n):
	print(*(min(A[i], B[j]) if h else 0 for (i, h) in enumerate(I())))


(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()


(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
for y in range(n):
	row = input().split()
	print(' '.join([str(min(front[x], left[y]) if c is '1' else 0) for (x, c) in enumerate(row)]))


(n, m, h) = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
t = []
for _ in range(n):
	t.append([int(item) for item in input().split()])
h = [[-1] * m for _ in range(n)]
for i in range(n):
	for j in range(m):
		if t[i][j] == 0:
			h[i][j] = 0
		else:
			h[i][j] = min(a[j], b[i])
for line in h:
	print(*line)


import sys

def input():
	return sys.stdin.readline().strip()

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

def get():
	return map(int, input().split())

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	from math import ceil
	(n, m, h) = get()
	forward = [int(i) for i in input().split()]
	left = [int(i) for i in input().split()]
	up = [[int(i) for i in input().split()] for j in range(n)]
	ans = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if up[i][j] == 1:
				ans[i][j] = min(left[i], forward[j])
	for i in range(n):
		print(*ans[i])
main()


(l, w, h) = map(int, input().split(' '))
lng = list(map(int, input().split(' ')))
width = list(map(int, input().split(' ')))
hgt = list()
for x in range(l):
	hgt.append(list(map(int, input().split(' '))))
for x in range(l):
	for y in range(w):
		if hgt[x][y] == 1:
			hgt[x][y] = min(width[x], lng[y])
out = ''
for x in range(l):
	for y in range(w):
		out += str(hgt[x][y]) + ' '
	print(out)
	out = ''


data = list(map(int, input().split()))
n = data[0]
m = data[1]
h = data[2]
mList = list(map(int, input().split()))
nList = list(map(int, input().split()))
hList = []
for i in range(n):
	hList.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if hList[i][j] == 1:
			hList[i][j] = min(nList[i], mList[j])
for i in range(n):
	s = ''
	for j in range(m):
		s += str(hList[i][j]) + ' '
	print(s)


(N, M, H) = 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(N)]
for i in range(N):
	print(' '.join(map(str, [min(left[i], front[j]) if top[i][j] == 1 else 0 for j in range(M)])))


(n, m, h) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f = []
for _ in range(n):
	f.append(list(map(int, input().split())))
for x in range(n):
	for y in range(m):
		if f[x][y] == 1:
			f[x][y] = min(a[y], b[x])
	print(' '.join(map(str, f[x])))


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


(n, m, h) = map(int, input().split())
front_view = list(map(int, input().split()))
left_view = list(map(int, input().split()))
data = []
for pos in range(n):
	item = list(map(int, input().split()))
	data.append(item)
for row in range(n):
	for column in range(m):
		if data[row][column] == 0:
			continue
		else:
			high = min(front_view[column], left_view[row])
			data[row][column] = high
	print(*data[row])


(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) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	t = list(map(int, input().split()))
	print(' '.join((str(min(a[j], b[i]) if v != 0 else 0) for (j, v) in enumerate(t))))


import sys
input = sys.stdin.readline
(n, m, h) = map(int, input().split())
maze = [[0] * m for _ in range(n)]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
Q = []
for i in range(n):
	for (j, v) in enumerate(map(int, input().split())):
		if v == 1:
			maze[i][j] = min(a[j], b[i])
for i in maze:
	print(*i)


(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, m, h) = list(map(int, input().split()))
frontmat = list(map(int, input().split()))
leftmat = list(map(int, input().split()))
topview = []
for nn in range(n):
	topview.append(list(map(int, input().split())))
result = list(topview)
for i in range(len(result)):
	for j in range(len(result[0])):
		if result[i][j] > 0:
			result[i][j] = min(frontmat[j], leftmat[i])
for row in result:
	print(' '.join(map(str, row)))


(n, m, h) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
H = []
for i in range(n):
	H.append(list(map(int, input().split())))
ans = [[0] * m for i in range(n)]
for y in range(n):
	for x in range(m):
		ans[y][x] = min(A[x], B[y], H[y][x] * h)
for y in range(n):
	print(' '.join(list(map(str, ans[y]))))


(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()


R = lambda : map(int, input().split())
(n, m, h) = R()
a = tuple(R())
b = tuple(R())
for i in range(n):
	t = list(R())
	for (j, tt) in enumerate(t):
		if tt:
			t[j] = min(a[j], b[i])
	print(*t, sep=' ')


(m, n, h) = list(map(int, input().split()))
fronts = list(map(int, input().split()))
rows = list(map(int, input().split()))
nums = []
for i in range(m):
	row = []
	for (idx, j) in enumerate(list(map(int, input().split()))):
		if j == 1:
			row.append(min(fronts[idx], rows[i]))
		else:
			row.append(0)
	nums.append(row)
for ele in nums:
	print(*ele)


from sys import stdin
(n, m, h) = list(map(int, stdin.readline().split()))
cols = list(map(int, stdin.readline().split()))
rows = list(map(int, stdin.readline().split()))
top = [list(map(int, stdin.readline().split())) for i in range(n)]
ans = [[0 if top[i][f] == 0 else min(rows[i], cols[f]) for f in range(m)] for i in range(n)]
print('\n'.join([' '.join(map(str, r)) for r in ans]))


def main():
	(n, m, h) = input().split()
	n = int(n)
	m = int(m)
	h = int(h)
	m_array = [int(i) for i in input().split()]
	n_array = [int(j) for j in input().split()]
	mat = []
	for i in range(n):
		row = [int(j) for j in input().split()]
		mat.append(row)
	i = 0
	while i <= n - 1:
		s = ''
		for j in range(m):
			if mat[i][j] == 0:
				s = s + ' ' + '0'
			else:
				u = min(m_array[j], n_array[i])
				s = s + ' ' + str(u)
		print(s)
		i += 1
main()


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
n = a[0]
m = a[1]
h = a[2]
l = []
for i in range(n):
	d = list(map(int, input().split()))
	l.append(d)
	n -= 1
for i in range(0, a[1]):
	for j in range(0, a[0]):
		if l[j][i] == 1:
			l[j][i] = b[i]
for i in range(0, a[0]):
	for j in range(0, a[1]):
		if l[i][j] > c[i]:
			l[i][j] = c[i]
for i in range(0, a[0]):
	print(*l[i])


from operator import mul
(n, m, h) = map(int, input().split())
H = [list(map(int, input().split()))] * n
c = list(map(int, input().split()))
for (i, hc) in enumerate(c):
	H[i] = [min(hc, v) for v in H[i]]
for i in range(n):
	t = list(map(int, input().split()))
	print(' '.join((str(v) for v in map(mul, H[i], t))))


(n, m, h) = map(int, input().split())
front_view = list(map(int, input().split()))
left_view = list(map(int, input().split()))
for i in range(n):
	l = list(map(int, input().split()))
	for j in range(m):
		if l[j]:
			if j != m - 1:
				print(min(front_view[j], left_view[i]), end=' ')
			else:
				print(min(front_view[j], left_view[i]))
		elif j != m - 1:
			print(0, end=' ')
		else:
			print(0)


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()


import sys, math, queue
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
side = list(map(int, input().split()))
top = []
for i in range(n):
	top.append(list(map(int, input().split())))
ans = [[-1 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if top[i][j] == 0:
			ans[i][j] = 0
		else:
			ans[i][j] = min(front[j], side[i])
for row in ans:
	print(*row)


(n, m, h) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [[0] * m for _ in range(n)]
for i in range(n):
	for j in range(m):
		l[i][j] = min(a[j], b[i])
for i in range(n):
	p = list(map(int, input().split()))
	for j in range(m):
		if p[j] == 0:
			l[i][j] = 0
for i in l:
	print(*i)


(n, m, h) = map(int, input().split())
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
top = [[int(x) for x in input().split()] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if top[i][j]:
			top[i][j] = min(front[j], left[i])
for line in top:
	print(' '.join(map(str, line)))


(n, m, h) = map(int, input().split())
mm = list(map(int, input().split()))
nn = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			a[i][j] = min(mm[j], nn[i])
for i in range(n):
	print(*a[i])


(n, m, h) = map(int, input().split())
c = list(map(int, input().split()))
r = list(map(int, input().split()))
matrix = []
for i in range(n):
	x = list(map(int, input().split()))
	for j in range(m):
		if x[j]:
			if c[j] <= r[i]:
				x[j] = c[j]
			else:
				x[j] = r[i]
	matrix.append(x)
for i in matrix:
	print(*i)


(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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mat = [0] * n
for i in range(n):
	k = list(map(int, input().split()))
	mat[i] = k
for i in range(m):
	if a[i] == 0:
		continue
	for j in range(n):
		if mat[j][i] != 0:
			mat[j][i] = a[i]
for i in range(n):
	if b[i] == 0:
		continue
	for j in range(m):
		if mat[i][j] != 0:
			if mat[i][j] >= b[i]:
				mat[i][j] = b[i]
for i in range(n):
	print(*mat[i])


import math

def main():
	(n, m, h) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	top_view = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if top_view[i][j]:
				if a[j] == b[i]:
					top_view[i][j] = a[j]
				else:
					top_view[i][j] = min(b[i], a[j]) if b[i] != 0 and a[j] != 0 else a[j] if b[i] == 0 else b[i]
	for i in top_view:
		print(*i)
main()


(n, m, _) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = [list(map(int, input().split())) for _ in range(n)]
ans = [[None] * m for _ in range(n)]
for i in range(n):
	for j in range(m):
		ans[i][j] = min(b[i], a[j]) if h[i][j] else 0
for i in range(n):
	print(*ans[i])


(n, m, h) = map(int, input().split())
M = tuple(map(int, input().split()))
N = tuple(map(int, input().split()))
G = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if not G[i][j]:
			continue
		G[i][j] = min(N[i], M[j])
for i in range(n):
	print(*G[i])


(n, m, h) = [int(i) for i in input().split()]
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
lst = list()
for x in range(n):
	lst.append([int(z) for z in input().split()])
result = list(lst)
for i in range(len(result)):
	for j in range(len(result[0])):
		if result[i][j] > 0:
			result[i][j] = min(a[j], b[i])
for row in result:
	print(' '.join(map(str, row)))


(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()


(n, m, h) = [int(x) for x in input('').split(' ')]
M = [int(x) for x in input('').split(' ')]
N = [int(x) for x in input('').split(' ')]
H1 = []
for i in range(n):
	H1.append([int(x) for x in input('').split(' ')])
for i in range(n):
	for j in range(m):
		if H1[i][j] > 0:
			print(min(M[j], N[i]), end=' ')
		else:
			print(0)
	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()]
arr = []
for i in range(n):
	arr.append([int(i) for i in input().split()])
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if arr[i][j] > 0:
			ans[i][j] = min(a[j], b[i])
for i in ans:
	print(*i)


(n, m, h) = map(int, input().split())
F = list(map(int, input().split()))
L = list(map(int, input().split()))
a = []
for i in range(n):
	s = list(map(int, input().split()))
	a.append(s)
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			a[i][j] = min(F[j], L[i])
for i in a:
	print(*i)


def main():
	(n, m, h) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	g = []
	for _ in range(n):
		g.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if g[i][j] > 0:
				g[i][j] = min(a[j], b[i])
	for i in range(n):
		print(*g[i])
main()


(n, m, h) = [int(x) for x in input().split()]
ms = [int(x) for x in input().split()]
ns = [int(x) for x in input().split()]
dp = [[None] * m for i in range(n)]
for i in range(n):
	tem = [int(x) for x in input().split()]
	for j in range(m):
		if tem[j] == 0:
			dp[i][j] = str(0)
		else:
			dp[i][j] = str(min(ms[j], ns[i]))
	print(' '.join(dp[i]))


(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = [list(map(int, input().split())) for _ in range(n)]
block = [[0] * m for _ in range(n)]
for r in range(n):
	for c in range(m):
		block[r][c] = top[r][c] * min(front[c], left[r])
for r in range(n):
	print(' '.join([str(x) for x in block[r]]))


(n, m, h) = (int(x) for x in input().split())
table = [[0] * m for _ in range(n)]
view = [int(x) for x in input().split()]
for (j, my_max) in enumerate(view):
	for i in range(n):
		table[i][j] = my_max
view = [int(x) for x in input().split()]
for (i, my_max) in enumerate(view):
	for j in range(m):
		table[i][j] = min(table[i][j], my_max)
view = [[int(x) for x in input().split()] for i in range(n)]
for (i, row) in enumerate(view):
	for (j, val) in enumerate(row):
		if val == 0:
			table[i][j] = 0
for row in table:
	print(*row)


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


(n, m, h) = map(int, input().split())
col = list(map(int, input().split()))
row = list(map(int, input().split()))
field = []
for i in range(n):
	next = list(map(int, input().split()))
	field.append(next)
for r in range(n):
	for c in range(m):
		if field[r][c] == 1:
			field[r][c] = min(row[r], col[c])
for v in field:
	print(*v)


(n, m, h) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
ans = [[0] * m for i in range(n)]
for i in range(n):
	c.append(list(map(int, input().split())))
for i in range(m):
	for j in range(n):
		if c[j][i] and a[i] <= b[j]:
			ans[j][i] = a[i]
			break
for j in range(n):
	for i in range(m):
		if c[j][i] and b[j] <= a[i]:
			ans[j][i] = b[j]
			break
for i in range(n):
	for j in range(m):
		if c[i][j] and (not ans[i][j]):
			ans[i][j] = 1
for i in range(n):
	print(*ans[i])


(n, m, h) = map(int, input().strip().split())
front_view = [int(i) for i in input().strip().split()]
left_view = [int(i) for i in input().strip().split()]
above = [[int(i) - 1 for i in input().strip().split()] for i in range(n)]
need_to_have = []
for i in range(n):
	to_put = 0
	for j in range(m):
		if left_view[i] == front_view[j] and above[i][j] == 0:
			above[i][j] = left_view[i]
			break
	need_fill = True
	for j in range(m):
		if above[i][j] == left_view[i]:
			need_fill = False
			break
	if need_fill:
		for j in range(m):
			if above[i][j] == 0 and front_view[j] >= left_view[i]:
				above[i][j] = left_view[i]
				break
for i in range(m):
	need_fill = True
	for j in range(n):
		if above[j][i] == front_view[i]:
			need_fill = False
			break
	if need_fill:
		for j in range(n):
			if above[j][i] == 0 and left_view[j] >= front_view[i]:
				above[j][i] = front_view[i]
				break
for i in range(n):
	print(' '.join([str(j if j > 0 else j + 1) for j in above[i]]))


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()


from sys import stdin

def solve():
	(N, M, H) = map(int, stdin.readline().split())
	front = [int(k) for k in stdin.readline().split()]
	left = [int(k) for k in stdin.readline().split()]
	result = []
	for i in range(N):
		top = [int(k) for k in stdin.readline().split()]
		for j in range(M):
			if top[j] == 1:
				top[j] = min(front[j], left[i])
		result.append(' '.join(map(str, top)))
	print('\n'.join(result))
solve()


(a, b, h) = map(int, input().split())
m = list(map(int, input().split()))
n = list(map(int, input().split()))
mat = []
for i in range(a):
	x = list(map(int, input().split()))
	mat.append(x)
for i in range(a):
	for j in range(b):
		if mat[i][j] == 1:
			mat[i][j] = min(n[i], m[j])
for i in range(a):
	for j in range(b):
		print(mat[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()


p = print
(r, c, h) = map(int, input().split())
m = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
flag = []
for i in range(r):
	x = []
	x = list(map(int, input().split()))
	m.append(x)
for i in range(r):
	for j in range(c):
		if m[i][j] == 1:
			m[i][j] = min(a[j], b[i])
for i in range(r):
	print(*m[i])


from sys import stdin, exit
(l, w, h) = map(int, stdin.readline().split())
f = list(map(int, stdin.readline().split()))
le = list(map(int, stdin.readline().split()))
t = []
for i in range(l):
	h = list(map(int, stdin.readline().split()))
	t.append(h)
for i in range(l):
	for j in range(len(t[i])):
		if t[i][j] == 1:
			if f[j] != 0 and f[j] <= le[i]:
				t[i][j] = f[j]
for i in range(l):
	flag = 1
	for j in range(len(t[i])):
		if t[i][j] == le[i]:
			flag = 0
			continue
	if flag == 1:
		for j in range(len(t[i])):
			if t[i][j] == 1 and le[i] <= f[j]:
				t[i][j] = le[i]
for i in range(l):
	for j in range(len(t[i])):
		print(str(t[i][j]) + ' ', end='')
	print()


import sys
input = sys.stdin.readline
(n, m, h) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
MAP = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if MAP[i][j] == 0:
			continue
		MAP[i][j] = min(A[j], B[i])
for m in MAP:
	print(*m)


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()


def printGrid(grid):
	for i in range(len(grid)):
		print(' '.join(grid[i]))
(n, m, h) = map(int, input().strip().split())
fv = list(map(int, input().strip().split()))
lv = list(map(int, input().strip().split()))
grid = [list(map(int, input().strip().split())) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if grid[i][j]:
			grid[i][j] = str(min(fv[j], lv[i]))
		else:
			grid[i][j] = str(0)
printGrid(grid)


(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):
	line = map(int, input().split())
	top.append(list(line))
for i in range(n):
	for j in range(m):
		if top[i][j] != 0:
			top[i][j] = min(left[i], front[j])
for l in top:
	for (i, c) in enumerate(l):
		if i == m - 1:
			print(c)
		else:
			print(c, end=' ')


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


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = [list(map(int, input().split())) for _ in range(n)]
ans = [[min(a[i], b[j]) * h[j][i] for i in range(m)] for j in range(n)]
for i in ans:
	print(*i)


import collections
(m, n, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
up = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
	for j in range(n):
		if up[i][j]:
			up[i][j] = min(left[i], front[j])
for row in up:
	print(' '.join((str(i) for i in row)))


import sys
input = sys.stdin.readline
from collections import *
(n, m, h) = map(int, input().split())
ans = [[0] * m for _ in range(n)]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if c[i][j] == 1:
			ans[i][j] = min(a[j], b[i])
for ans_i in ans:
	print(*ans_i)


(n, m, h) = [int(elm) for elm in input().split(' ')]
a_list = [int(elm) for elm in input().split(' ')]
b_list = [int(elm) for elm in input().split(' ')]
e_map = [[int(elm) for elm in input().split(' ')] for _ in range(n)]
h_map = [[-e_map[j][i] for i in range(m)] for j in range(n)]

def first_update():
	first_update1()
	change = first_update2()
	while change:
		change1 = first_update1()
		change2 = first_update2()
		print(change1, change2)
		change = change1 or change2

def first_update1():
	first = True
	while first or change:
		first = False
		change = False
		for j in range(n):
			one_coords = []
			for i in range(m):
				if e_map[j][i] == 1:
					if h_map[j][i] == -1:
						pass
			one_coords = [[i, j] for i in range(m) if h_map[j][i] == -1]
			ones = [[i, j] for i in range(m) if h_map[j][i] == -1]
			if len(one_coords) == 1:
				(i0, j0) = one_coords[0]
				h_map[j0][i0] = b_list[j]
				change = True
		for i in range(m):
			one_coords = [[i, j] for j in range(n) if h_map[j][i] == -1]
			if len(one_coords) == 1:
				(i0, j0) = one_coords[0]
				h_map[j0][i0] = a_list[i]
				change = True
	return change

def first_update2():
	change = False
	return change

def update():
	h_map = [[min(a_list[i], b_list[j]) if e_map[j][i] == 1 else 0 for i in range(m)] for j in range(n)]
	return h_map
loop = True
while loop:
	h_map = update()
	loop = False
for elms in h_map:
	line = ' '.join([str(elm) for elm in elms])
	print(line)


(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(' ')]
res = []
for ni in range(n):
	bn = b[ni]
	nums = [int(v) for v in input().split(' ')]
	nums = [v * a[i] if a[i] <= bn else v * bn for (i, v) in enumerate(nums)]
	print(' '.join((str(i) for i in nums)))
	res.append(nums)


(n, m, h) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
H = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if H[i][j] == 1:
			H[i][j] = min(A[j], B[i])
for s in H:
	print(*s)


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

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

def mi():
	return map(int, input().split())
(a, b, c) = mi()
sb = si()
sa = si()
ss = [si() for i in range(a)]
ans = [[c for i in range(b)] for i in range(a)]
for i in range(a):
	for x in range(b):
		ans[i][x] = ss[i][x] * min(c, sa[i], sb[x])
for i in ans:
	print(*i)


kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, m, h) = kk()
front = ll()
left = ll()
for col in range(n):
	tbp = []
	line = kk()
	for (row, l) in enumerate(line):
		tbp.append(0 if l == 0 else min(front[row], left[col]))
	print(*tbp)


(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
a = []
for i in range(n):
	s = list(map(int, input().split()))
	a.append(s)
for j in range(m):
	for i in range(n):
		if a[i][j] == 1:
			a[i][j] = front[j]
for i in range(n):
	for j in range(m):
		a[i][j] = min(a[i][j], left[i])
for elem in a:
	print(*elem)


(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 = []
pro = {}
for i in range(n):
	pro[i] = 0
answer = [[0] * m for i in range(n)]
for i in range(n):
	a = [int(x) for x in input().split()]
	up.append(a)
for i in range(m):
	for j in range(n):
		if front[i] == left[j] and up[j][i] == 1 and (pro[j] == 0):
			answer[j][i] = front[i]
			pro[j] = 1
			break
	else:
		for j in range(n):
			if front[i] <= left[j] and up[j][i] == 1:
				answer[j][i] = front[i]
for i in range(n):
	for j in range(m):
		if answer[i][j] == 0 and up[i][j] == 1:
			if pro[i] == 0 and front[j] >= left[i]:
				answer[i][j] = left[i]
				pro[i] = 1
			else:
				answer[i][j] = 1
for item in answer:
	print(*item)


(n, m, h) = map(int, input().split())
d = [[0] * m for i in range(n)]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	c = list(map(int, input().split()))
	for j in range(m):
		if c[j] == 0:
			d[i][j] = 0
		else:
			d[i][j] = min(b[i], a[j])
	print(' '.join(map(str, d[i])))


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
structure = []
for i in range(n):
	structure.append(list(map(int, input().split())))
for i in range(m):
	for j in range(n):
		if a[i] == b[j] and structure[j][i] == 1:
			structure[j][i] = a[i]
for i in range(n):
	if max(structure[i]) == b[i]:
		pass
	else:
		for j in range(m):
			if structure[i][j] == 1 and b[i] <= a[j]:
				structure[i][j] = b[i]
				break
for i in range(m):
	maxi = 0
	for j in range(n):
		maxi = max(maxi, structure[j][i])
	if maxi == a[i]:
		pass
	else:
		for j in range(n):
			if structure[j][i] == 1 and a[i] <= b[j]:
				structure[j][i] = a[i]
				break
for i in range(n):
	print(' '.join(map(str, structure[i])))


(N, M, H) = map(int, input().split())
F = [int(a) for a in input().split()]
L = [int(a) for a in input().split()]
T = [[int(a) for a in input().split()] for i in range(N)]
X = [[T[i][j] for j in range(M)] for i in range(N)]
for j in range(M):
	if F[j] > 0:
		for i in range(N):
			if T[i][j] > 0 and L[i] >= F[j]:
				X[i][j] = F[j]
				break
for i in range(N):
	if L[i] > 0:
		for j in range(M):
			if T[i][j] > 0 and L[i] <= F[j]:
				X[i][j] = L[i]
				break
for x in X:
	print(*x)


(length, width, height) = [int(x) for x in input().split()]
front = [int(x) for x in input().split()[:width]]
left = [int(x) for x in input().split()[:length]]
a = list()
for i in range(length):
	a = [int(x) for x in input().split()]
	for j in range(width):
		if a[j] == 1:
			a[j] = front[j]
		if a[j] > 0 and left[i] < a[j]:
			a[j] = left[i]
	a = [str(x) for x in a]
	print(' '.join(a))


(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()


import math
intputs = input().split()
n = int(intputs[0])
m = int(intputs[1])
h = int(intputs[2])
a = []
b = []
mat = []
result = []
intputs = input().split()
a = [int(i) for i in intputs]
intputs = input().split()
b = [int(i) for i in intputs]
for i in range(n):
	intputs = input().split()
	temp = [int(i) for i in intputs]
	mat.append(temp)
for i in range(n):
	for j in range(m):
		if b[i] == a[j] and mat[i][j] == 1:
			mat[i][j] = b[i]
		elif b[i] > a[j] and mat[i][j] == 1:
			mat[i][j] = a[j]
		elif b[i] < a[j] and mat[i][j] == 1:
			mat[i][j] = b[i]
		if j == m - 1:
			print(mat[i][j])
		else:
			print(mat[i][j], end=' ')


from collections import defaultdict
(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
df = defaultdict(list)
dl = defaultdict(list)
for i in range(n):
	df[i + 1] = list(map(int, input().split()))
	for j in range(m):
		dl[j + 1].append(df[i + 1][j])
ans = [[0] * m for x in range(n)]
for i in range(m):
	for j in range(n):
		if dl[i + 1][j]:
			ans[j][i] = min(b[j], a[i])
for i in range(n):
	print(*ans[i])


(n, m, h) = list(map(int, input().split()))
front = list(map(int, input().split()))
left = list(map(int, input().split()))
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
maxs = []
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 1:
			matrix[i][j] = front[j]
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] > left[i]:
			matrix[i][j] = left[i]
for i in range(len(matrix)):
	print(*matrix[i])


(n, m, h) = map(int, input().split())
mcol = list(map(int, input().split()))
mrow = list(map(int, input().split()))
ans = []
for i in range(n):
	ans.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if ans[i][j] == 1:
			ans[i][j] = min(mcol[j], mrow[i])
for i in range(n):
	print(*ans[i])


import sys

def gridmaker(r, c, rowheights, colheights, sourcegrid):
	grid = sourcegrid
	for i in range(r):
		for j in range(c):
			if grid[i][j] > 0:
				grid[i][j] = min(rowheights[i], colheights[j])
	return grid
(n, m, h) = [int(x) for x in input().split()]
colheights = [int(x) for x in input().split()]
rowheights = [int(x) for x in input().split()]
sourcegrid = []
for _ in range(n):
	sourcegrid.append([int(x) for x in input().split()])
for row in gridmaker(n, m, rowheights, colheights, sourcegrid):
	print(' '.join([str(x) for x in row]))


(n, m, h) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
an = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if an[i][j] != 0:
			an[i][j] = min(B[i], A[j])
	print(' '.join(map(str, an[i])))


import functools

def solve():
	(n, m, _) = [int(i) for i in str.split(input(), ' ')]
	front = [int(i) for i in str.split(input(), ' ')]
	left = [int(i) for i in str.split(input(), ' ')]
	top = [[int(i) for i in str.split(input(), ' ')] for _ in range(n)]
	res = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if top[i][j] == 1:
				res[i][j] = min(left[i], front[j])
	for i in range(n):
		print(functools.reduce(lambda x, y: str(x) + ' ' + str(y), res[i]))
solve()


(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) = map(int, input().split())
s1 = [int(x) for x in input().split()]
s2 = [int(x) for x in input().split()]
L = []
for i in range(0, n):
	h = [int(x) for x in input().split()]
	L.append(h)
dp = []
for i in range(0, len(L)):
	h = []
	for j in range(0, len(L[i])):
		h.append(0)
	dp.append(h)
for i in range(0, len(dp)):
	temp = s2[i]
	for j in range(0, len(dp[i])):
		flag = s1[j]
		if L[i][j] != 0:
			dp[i][j] = min(temp, flag)
for i in range(0, len(dp)):
	for j in range(0, len(dp[i])):
		print(dp[i][j], 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())
frnt = list(map(int, input().split()))
lft = list(map(int, input().split()))
res = []
for i in range(n):
	row = list(map(int, input().split()))
	resr = []
	for j in range(m):
		if row[j] == 1:
			resr.append(min(lft[i], frnt[j]))
		else:
			resr.append(0)
	res.append(resr)
for i in range(n):
	print(*res[i])


(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()]
for i in range(n):
	c = [int(e) for e in input().split()]
	for j in range(m):
		c[j] = min(b[i], a[j]) if c[j] > 0 else 0
	print(' '.join((str(e) for e in c)))


(n, m, h) = [int(i) for i in input().split()]
front = [int(i) for i in input().split()]
left = [int(i) for i in input().split()]
A = []
for i in range(n):
	B = [int(i) for i in input().split()]
	A.append(B)
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if A[i][j]:
			ans[i][j] = min(front[j], left[i])
for i in ans:
	print(*i)


(n, m, h) = [int(i) for i in input().split()]
vc = [int(i) for i in input().split()]
vl = [int(i) for i in input().split()]
matr = []
for i2 in range(n):
	matr.append([int(i) for i in input().split()])
	for i3 in range(m):
		if matr[-1][i3] == 1:
			matr[-1][i3] = min(vc[i3], vl[i2])
for i2 in range(n):
	print(*matr[i2])


(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)]
for i in range(n):
	top[i] = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		top[i][j] = top[i][j] * min(left[i], front[j])
for i in range(n):
	print(' '.join(list(map(str, top[i]))))


(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()


(n, m, h) = map(int, input().split())
res = [[-1 for _ in range(m)] for _ in range(n)]
for (i, h) in enumerate([int(x) for x in input().split()]):
	for j in range(n):
		res[j][i] = h
for (i, h) in enumerate([int(x) for x in input().split()]):
	for j in range(m):
		if res[i][j] > h:
			res[i][j] = h
for r in range(n):
	for (c, h) in enumerate([int(x) for x in input().split()]):
		res[r][c] *= h
print(str(res).replace('], [', '\n').replace(',', '').replace('[[', '').replace(']]', ''))


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	print(*map(lambda z: z[1] * min(a[z[0]], b[i]), enumerate(map(int, input().split()))))


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
import re
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 9

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
		if meh < 0:
			meh = 0
	return msf

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))

def chk(x, t):
	a = x[0]
	d = x[1]
	n = math.ceil((t - a) / d + 1)
	return a + (n - 1) * d
(n, m, h) = numIN()
front = list(numIN())
left = list(numIN())
top = []
for _ in range(n):
	top.append(list(numIN()))
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if top[i][j]:
			if left[i] > front[j]:
				ans[i][j] = front[j]
			else:
				ans[i][j] = left[i]
for i in ans:
	print(*i)


(n, m, h) = map(int, input().split())
H = [list(map(int, input().split()))] * n
c = list(map(int, input().split()))
for (i, hc) in enumerate(c):
	H[i] = [min(hc, v) for v in H[i]]
for i in range(n):
	t = list(map(int, input().split()))
	print(' '.join((str(a * b) for (a, b) in zip(H[i], t))))


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, _) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if h[i][j]:
			h[i][j] = min(a[j], b[i])
print('\n'.join((' '.join(map(str, row)) for row in h)))


(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()]
top = []
for i in range(n):
	topLine = [int(i) for i in input().split()]
	top.append(topLine)
for i in range(n):
	for j in range(m):
		if top[i][j] == 1:
			top[i][j] = min(a[j], b[i])
for i in range(n):
	res = str(top[i][0])
	for j in range(1, m):
		res += ' ' + str(top[i][j])
	print(res)


(n, m, h) = list(map(int, input().split()))
front = list(map(int, input().split()))
back = list(map(int, input().split()))
top = [list(map(int, input().split())) for _ in range(n)]
for y in range(n):
	for x in range(m):
		if top[y][x] == 1:
			top[y][x] = min(front[x], back[y])
for y in range(n):
	print(' '.join(map(str, top[y])))


from collections import defaultdict
(n, m, h) = list(map(int, input().split()))
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = []
for la in range(n):
	top_layer = list(map(int, input().split()))
	top.append(top_layer)
	for (i, val) in enumerate(top_layer):
		if val == 1 and front[i] <= left[la]:
			top[la][i] = front[i]
		elif val == 1 and front[i] >= left[la]:
			top[la][i] = left[la]
for i in range(len(top)):
	print(*top[i])


(nRows, nCols, h) = map(int, input().split())
col = list(map(int, input().split()))
row = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(nRows)]
for r in range(nRows):
	for c in range(nCols):
		if a[r][c] == 1:
			a[r][c] = min(row[r], col[c])
for r in a:
	print(*r)


(n, m, h) = list(map(int, input().split()))
aj = list(map(int, input().split()))
ai = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			a[i][j] = min(ai[i], aj[j])
for i in range(n):
	print(' '.join(list(map(str, a[i]))))


(n, m, h) = map(int, input().split())
a = []
c = list(map(int, input().split()))
r = list(map(int, input().split()))
for _ in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			continue
		a[i][j] = min(r[i], c[j])
for i in a:
	print(*i)


a = input().split()
n = int(a[0])
m = int(a[1])
h = int(a[2])
b = input().split()
fv = [int(b[i]) for i in range(m)]
b = input().split()
lv = [int(b[i]) for i in range(n)]
grid = []
for i in range(n):
	b = input().split()
	grid.append([int(b[i]) for i in range(m)])
for i in range(n):
	for j in range(m):
		if grid[i][j] == 1 and fv[j] >= lv[i]:
			grid[i][j] = lv[i]
			break
for i in range(m):
	for j in range(n):
		if grid[j][i] == 1 and fv[i] <= lv[j]:
			grid[j][i] = fv[i]
			break
for i in range(n):
	for j in range(m):
		print(grid[i][j], end=' ')
	print('\n')


def main(argc, argv) -> {}:
	sync_with_stdio(false)
	cin.tie(0)
	cout.tie(0)
	n = m = h = 0
	n <<= cin
	m <<= cin
	h <<= cin
	A = vector << int >> m
	A <<= cin
	B = vector << int >> n
	B <<= cin
	P = []
	board = []
	i = 0
	while i < n or {}:
		a = vector << int >> m
		a <<= cin
		P.append(a)
		board.append(vector << int >> m)
		i += 1
		{}
	k = 0
	while k < n * m or {}:
		(y, x) = divmod(k, m)
		if P[y][x] or {}:
			val = min(A[x], B[y])
			board[y][x] = val
			{}
		k += 1
		{}
	y = 0
	while y < n or {}:
		x = 0
		while x < m or {}:
			cout << board[y][x] << ' '
			x += 1
			{}
		cout << '\n'
		y += 1
		{}
	return 0
	{}
import base64
exec(base64.decodestring(b'cHkyID0gcm91bmQoMC41KQoKaWYgcHkyOgogICAgZnJvbSBmdXR1cmVfYnVpbHRpbnMgaW1wb3J0IGFzY2lpLCBmaWx0ZXIsIGhleCwgbWFwLCBvY3QsIHppcAogICAgcmFuZ2UgPSB4cmFuZ2UKCmRlZiBzeW5jX3dpdGhfc3RkaW8oYik6CiAgICBpZiBiOiByZXR1cm4KICAgIGltcG9ydCBvcywgc3lzCiAgICBmcm9tIGlvIGltcG9ydCBCeXRlc0lPLCBJT0Jhc2UKICAgIAogICAgIyBGYXN0SU8gZm9yIFB5UHkyIGFuZCBQeVB5MyAod29ya3Mgd2l0aCBpbnRlcmFjdGl2ZSkgYnkgUGFqZW5lZ29kCiAgICBjbGFzcyBGYXN0SShvYmplY3QpOgogICAgICAgIGRlZiBfX2luaXRfXyhzZWxmLCBmZD0wLCBidWZmZXJzaXplPTIqKjE0KToKICAgICAgICAgICAgc2VsZi5zdHJlYW0gPSBzdHJlYW0gPSBCeXRlc0lPKCk7IHNlbGYuYnVmZW5kbCA9IDAKICAgICAgICAgICAgZGVmIHJlYWQyYnVmZmVyKCk6CiAgICAgICAgICAgICAgICBzID0gb3MucmVhZChmZCwgYnVmZmVyc2l6ZSArIG9zLmZzdGF0KGZkKS5zdF9zaXplKTsgcG9zID0gc3RyZWFtLnRlbGwoKQogICAgICAgICAgICAgICAgc3RyZWFtLnNlZWsoMCwyKTsgc3RyZWFtLndyaXRlKHMpOyBzdHJlYW0uc2Vlayhwb3MpOyByZXR1cm4gcwogICAgICAgICAgICBzZWxmLnJlYWQyYnVmZmVyID0gcmVhZDJidWZmZXIKICAgICAgICAjIFJlYWQgZW50aXJlIGlucHV0CiAgICAgICAgZGVmIHJlYWQoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYucmVhZDJidWZmZXIoKTogcGFzcwogICAgICAgICAgICByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZCgpIGlmIHNlbGYuc3RyZWFtLnRlbGwoKSBlbHNlIHNlbGYuc3RyZWFtLmdldHZhbHVlKCkKICAgICAgICBkZWYgcmVhZGxpbmUoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYuYnVmZW5kbCA9PSAwOiBzID0gc2VsZi5yZWFkMmJ1ZmZlcigpOyBzZWxmLmJ1ZmVuZGwgKz0gcy5jb3VudChiIlxuIikgKyAobm90IHMpCiAgICAgICAgICAgIHNlbGYuYnVmZW5kbCAtPSAxOyByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZGxpbmUoKQogICAgICAgIGRlZiBpbnB1dChzZWxmKTogcmV0dXJuIHNlbGYucmVhZGxpbmUoKS5yc3RyaXAoYidcclxuJykKICAgICAgICAKICAgICAgICAjIFJlYWQgYWxsIHJlbWFpbmluZyBpbnRlZ2VycywgdHlwZSBpcyBnaXZlbiBieSBvcHRpb25hbCBhcmd1bWVudAogICAgICAgIGRlZiByZWFkbnVtYmVycyhzZWxmLCB6ZXJvPTApOgogICAgICAgICAgICBjb252ID0gb3JkIGlmIHB5MiBlbHNlIGxhbWJkYSB4OngKICAgICAgICAgICAgQSA9IFtdOyBudW1iID0gemVybzsgc2lnbiA9IDE7IGMgPSBiIi0iWzBdCiAgICAgICAgICAgIGZvciBjIGluIHNlbGYucmVhZCgpOgogICAgICAgICAgICAgICAgaWYgYyA+PSBiIjAiWzBdOiBudW1iID0gMTAgKiBudW1iICsgY29udihjKSAtIDQ4CiAgICAgICAgICAgICAgICBlbGlmIGMgPT0gYiItIlswXTogc2lnbiA9IC0xCiAgICAgICAgICAgICAgICBlbGlmIGMgIT0gYiJcciJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYik7IG51bWIgPSB6ZXJvOyBzaWduID0gMQogICAgICAgICAgICBpZiBjID49IGIiMCJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYikKICAgICAgICAgICAgcmV0dXJuIEEKICAgIAogICAgY2xhc3MgRmFzdE8oSU9CYXNlKToKICAgICAgICBkZWYgX19pbml0X18oc2VsZiwgZmQ9MSk6CiAgICAgICAgICAgIHN0cmVhbSA9IEJ5dGVzSU8oKQogICAgICAgICAgICBzZWxmLmZsdXNoID0gbGFtYmRhOiBvcy53cml0ZSgxLCBzdHJlYW0uZ2V0dmFsdWUoKSkgYW5kIG5vdCBzdHJlYW0udHJ1bmNhdGUoMCkgYW5kIHN0cmVhbS5zZWVrKDApCiAgICAgICAgICAgIHNlbGYud3JpdGUgPSBzdHJlYW0ud3JpdGUgaWYgcHkyIGVsc2UgbGFtYmRhIHM6IHN0cmVhbS53cml0ZShzLmVuY29kZSgpKQogICAgCiAgICBzeXMuc3RkaW4sIHN5cy5zdGRvdXQgPSBGYXN0SSgpLCBGYXN0TygpCiAgICBnbG9iYWwgaW5wdXQKICAgIGlucHV0ID0gc3lzLnN0ZGluLmlucHV0CgoKaW1wb3J0IHN5cwoKY2xhc3Mgb3N0cmVhbToKICAgIGRlZiBfX2xzaGlmdF9fKHNlbGYsYSk6CiAgICAgICAgaWYgYSA9PSBlbmRsOgogICAgICAgICAgICBzeXMuc3Rkb3V0LndyaXRlKCJcbiIpCiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoc3RyKGEpKQogICAgICAgIHJldHVybiBzZWxmCiAgICBkZWYgdGllKHNlbGYsIHZhbCk6cGFzcwpjb3V0ID0gb3N0cmVhbSgpCmVuZGwgPSBvYmplY3QoKQoKY2xhc3MgaXN0cmVhbToKICAgIHRpZWR0byA9IGNvdXQKICAgIGlucCA9IE5vbmUKICAgIGRlZiBfX3Jsc2hpZnRfXyhhLGIpOgogICAgICAgIGlmIGEudGllZHRvID09IGNvdXQ6CiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGlmIHR5cGUoYik9PXR1cGxlIG9yIHR5cGUoYik9PWxpc3Q6CiAgICAgICAgICAgIHJldHVybiB0eXBlKGIpKHR5cGUoYykoYS5nZXQoKSkgZm9yIGMgaW4gYikKICAgICAgICByZXR1cm4gdHlwZShiKShhLmdldCgpKQogICAgZGVmIHRpZShzZWxmLCB2YWwpOgogICAgICAgIHNlbGYudGllZHRvID0gdmFsCiAgICBkZWYgZ2V0KGEpOgogICAgICAgIHdoaWxlIG5vdCBhLmlucDoKICAgICAgICAgICAgYS5pbnAgPSBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpWzo6LTFdCiAgICAgICAgcmV0dXJuIGEuaW5wLnBvcCgpCmNpbiA9IGlzdHJlYW0oKQoKY2xhc3MgVmVjdG9yOgogICAgZGVmIF9fbHNoaWZ0X18oc2VsZiwgb3RoZXIpOgogICAgICAgIHNlbGYudHlwZSA9IG90aGVyCiAgICAgICAgcmV0dXJuIHNlbGYKICAgIGRlZiBfX3JzaGlmdF9fKHNlbGYsIG90aGVyKToKICAgICAgICBpZiB0eXBlKG90aGVyKSA9PSB0dXBsZToKICAgICAgICAgICAgcmV0dXJuIFtzZWxmLnR5cGUob3RoZXJbMV0pXSpvdGhlclswXQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBbc2VsZi50eXBlKCldKm90aGVyCnZlY3RvciA9IFZlY3RvcigpCg=='))
false = False
true = True
main(len(sys.argv), sys.argv)


(n, m, h) = map(int, input().split())
column = list(map(int, input().split()))
rows = list(map(int, input().split()))
l = []
for i in range(n):
	la = list(map(int, input().split()))
	l.append(la)
for i in range(n):
	for j in range(m):
		if l[i][j] == 1:
			l[i][j] = rows[i]
for i in range(m):
	for j in range(n):
		if l[j][i] != 0:
			z = l[j][i]
			if z >= column[i]:
				l[j][i] = column[i]
for i in range(n):
	print(*l[i])


(n, m, h) = list(map(int, input().split()))
a_m = list(map(int, input().split()))
b_n = list(map(int, input().split()))
a_b = []
h = []
for i in range(n):
	h.append(list(map(int, input().split())))
	for j in range(m):
		if h[i][j] > 0:
			if a_m[j] >= b_n[i]:
				h[i][j] = b_n[i]
			else:
				h[i][j] = a_m[j]
			a_b.append([a_m[j], b_n[i], i, j])
for i in range(n):
	h[i] = list(map(str, h[i]))
	print(' '.join(h[i]))


(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()


(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
grid = []
for _ in range(n):
	grid.append(list(map(int, input().split())))
(r_cnt, c_cnt) = ([0] * n, [0] * m)
d = {}
for i in range(n):
	for j in range(m):
		if grid[i][j]:
			grid[i][j] = min(left[i], front[j])
for row in grid:
	print(' '.join(map(str, row)))


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())
front = [int(z) for z in input().split()]
side = [int(z1) for z1 in input().split()]
rows = []
for l in range(n):
	rows.append([int(z0) for z0 in input().split()])
for i in range(n):
	for j in range(m):
		if rows[i][j] == 1:
			rows[i][j] = min(side[i], front[j])
strows = []
for r in rows:
	rows1 = [str(z) for z in r]
	strows.append(' '.join(rows1))
print('\n'.join(strows))


istr = input()
ilist = [int(i) for i in istr.split() if i != '']
(n, m, h) = (ilist[0], ilist[1], ilist[2])
istr = input()
main_view = [int(i) for i in istr.split() if i != '']
istr = input()
left_view = [int(i) for i in istr.split() if i != '']
top_view = []
for i in range(n):
	istr = input()
	top_view.append([int(i) for i in istr.split() if i != ''])
for i in range(n):
	for j in range(m):
		if top_view[i][j] != 0:
			top_view[i][j] = min(left_view[i], main_view[j])
for i in range(n):
	print(' '.join([str(j) for j in top_view[i]]))


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


M = lambda : list(map(int, input().strip().split()))
(n, m, h) = M()
front = M()
left = M()
top = [None] * n
for i in range(n):
	top[i] = M()
	for j in range(m):
		if top[i][j] != 0:
			top[i][j] = left[i]
for i in range(m):
	for j in range(n):
		if top[j][i] > front[i]:
			top[j][i] = front[i]
for i in range(n):
	print(' '.join((str(x) for x in top[i])))


(n, m, max_h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [list(map(int, input().split())) for i in range(n)]
A = [[0] * m for i in range(n)]
for i in range(m):
	if a[i] > 0:
		for j in range(n):
			if a[i] <= b[j] and t[j][i] == 1:
				A[j][i] = a[i]
				break
for i in range(n):
	for j in range(m):
		if t[i][j] == 1 and A[i][j] == 0:
			A[i][j] = min(a[j], b[i])
for i in range(n):
	print(*A[i])


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
mod = 10 ** 9 + 7
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	max_so_far = -sys.maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return (max_so_far, start, end)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	(n, m, h) = num_input()
	front = list_input()
	left = list_input()
	mat = []
	for i in range(n):
		mat.append(list_input())
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 1:
				mat[i][j] = min(front[j], left[i])
	for i in mat:
		print(*i)
t = 1
for _ in range(t):
	solve()


(n, m, h) = [int(x) for x in input().split(' ')]
front_height = [int(x) for x in input().split(' ')]
left_height = [int(x) for x in input().split(' ')]
M = [[] * m] * n
for i in range(0, n):
	M[i] = [int(x) for x in input().split(' ')]
result = [0] * n
for i in range(0, n):
	result[i] = [0] * m
for i in range(0, n):
	for j in range(0, m):
		if M[i][j] == 1:
			result[i][j] = min(left_height[i], front_height[j])
for i in range(0, n):
	for j in range(0, m):
		if j != m - 1:
			print(result[i][j], end=' ')
		else:
			print(result[i][j])


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
mat = []
for _ in range(a[0]):
	d = [int(i) for i in input().split()]
	mat.append(d)
for i in range(0, a[1]):
	for j in range(0, a[0]):
		if mat[j][i] == 1:
			mat[j][i] = b[i]
for i in range(0, a[0]):
	for j in range(0, a[1]):
		if mat[i][j] > c[i]:
			mat[i][j] = c[i]
for i in range(0, len(mat)):
	print(*mat[i])


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


def main():
	(n, m, h) = map(int, input().split(' '))
	a = [None] + list(map(int, input().split(' ')))
	b = [None] + list(map(int, input().split(' ')))
	c = [None] + [[0] + list(map(int, input().split(' '))) for i in range(n)]
	r = [None] + [[0] * (m + 1) for i in range(n)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if c[i][j] == 0:
				continue
			r[i][j] = min(b[i], a[j])
	for i in range(1, n + 1):
		print(' '.join(map(str, r[i][1:])))
main()


(n, m, h) = map(int, input().split())
a = [0 for i in range(m)]
a[0:m] = map(int, input().split())
b = [0 for i in range(n)]
b[0:n] = map(int, input().split())
toy = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	toy[i][0:m] = map(int, input().split())
	for j in range(m):
		if toy[i][j] > 0:
			toy[i][j] = min(a[j], b[i])
for i in range(n):
	pout = ''
	for j in range(m):
		if len(pout) > 0:
			pout += ' '
		pout += str(toy[i][j])
	print(pout)


(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().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = []
for i in range(n):
	top += [list(map(int, input().split()))]
ans = [[0 for i in range(m)] for j in range(n)]
for (col, colv) in enumerate(front):
	for (row, rowv) in enumerate(left):
		if rowv <= colv and top[row][col] == 1:
			ans[row][col] = rowv
		elif rowv > colv and top[row][col] == 1:
			ans[row][col] = colv
for a in ans:
	print(' '.join([str(aa) for aa in a]))


import copy
(n, m, h) = input().split()
n = int(n)
m = int(m)
h = int(h)
M = []
N = []
H = []
M = input().split()
for i in range(0, m):
	M[i] = int(M[i])
N = input().split()
for i in range(0, n):
	N[i] = int(N[i])
for i in range(0, n):
	l = input().split()
	for j in range(0, len(l)):
		l[j] = int(l[j])
	H.append(copy.deepcopy(l))
L = []
for i in range(0, n):
	l = []
	L.append(copy.deepcopy(l))
	for j in range(0, m):
		L[i].append(0)
for i in range(0, n):
	for j in range(0, m):
		if H[i][j] == 1:
			if N[i] > M[j]:
				L[i][j] = M[j]
			else:
				L[i][j] = N[i]
for i in L:
	for j in i:
		print(j, ' ', end='')
	print()


(x, y, z) = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = []
for i in range(x):
	c.append([int(_) for _ in input().split()])
for i in range(x):
	for j in range(y):
		if c[i][j] == 1:
			c[i][j] = min(a[j], b[i])
for i in c:
	print(*i)


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lst = []
for i in range(n):
	lst.append(list(map(int, input().split())))
ans = []
for i in range(n):
	ans.append(lst[i][:])
for i in range(n):
	(ind, c) = (0, 0)
	for j in range(m):
		if lst[i][j] == 1:
			c += 1
			ind = j
	if c == 1:
		ans[i][ind] = b[i]
for i in range(m):
	(ind, c) = (0, 0)
	for j in range(n):
		if lst[j][i] == 1:
			c += 1
			ind = j
	if c == 1:
		ans[ind][i] = a[i]
for i in range(n):
	if max(ans[i]) < b[i]:
		for j in range(m):
			if lst[i][j] == 1 and b[i] <= a[j]:
				ans[i][j] = b[i]
				break
for i in range(m):
	maxx = 0
	for j in range(n):
		maxx = max(ans[j][i], maxx)
	if maxx < a[i]:
		for j in range(n):
			if lst[j][i] == 1 and a[i] <= b[j]:
				ans[j][i] = a[i]
				break
for i in range(n):
	print(' '.join(map(str, ans[i])))


(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()


import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, m, h) = mi()
a = li()
b = li()
g = [li() for i in range(n)]
for i in range(n):
	for j in range(m):
		if g[i][j] == 1:
			g[i][j] = None
z = [(a[i], i, 'a') for i in range(m)] + [(b[i], i, 'b') for i in range(n)]
for (val, i, c) in sorted(z):
	if c == 'a':
		for j in range(n):
			if g[j][i] is None:
				g[j][i] = val
	else:
		for j in range(m):
			if g[i][j] is None:
				g[i][j] = val
for row in g:
	print(*row)


def convert(string, list):
	cuv = ''
	for c in string:
		if c != ' ':
			cuv += c
		else:
			list.append(int(cuv))
			cuv = ''
	list.append(int(cuv))
l = []
lm = []
ln = []
s = input()
convert(s, l)
n = l[0]
m = l[1]
h = l[2]
s = input()
convert(s, lm)
s = input()
convert(s, ln)
for i in range(n):
	s = input()
	l = []
	convert(s, l)
	for j in range(m):
		if l[j] == 1:
			l[j] = min(ln[i], lm[j])
	print(*l)


(n, m, h) = map(int, input().split())
hs_along_m = [*map(int, input().split())]
hs_along_n = [*map(int, input().split())]
for i in range(n):
	ms = [*map(int, input().split())]
	o = []
	for j in range(m):
		if ms[j]:
			o.append(str(min(hs_along_m[j], hs_along_n[i])))
		else:
			o.append('0')
	print(' '.join(o))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, m, h) = map(int, input().split(' '))
fv = list(map(int, input().split(' ')))
lv = list(map(int, input().split(' ')))
tv = [list(map(int, input().split(' '))) for x in range(n)]
ans = [[0 for x in range(m)] for x in range(n)]
done = set()
for x in range(n):
	for y in range(m):
		maxheight = lv[x]
		if tv[x][y] == 1:
			for z in range(100, 0, -1):
				if z <= maxheight and z <= fv[y]:
					ans[x][y] = z
					break
for x in ans:
	print(*x)


def main():
	(n, m, h) = map(int, input().split())
	row = list(map(int, input().split()))
	col = list(map(int, input().split()))
	mat = [list(map(int, input().split())) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if mat[i][j]:
				mat[i][j] = min(col[i], row[j])
	for arr in mat:
		print(*arr)
	return 0
main()


(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()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007

def solve():
	t = 1
	for it in range(t):
		(n, m, h) = num()
		a = li()
		b = li()
		xp = [0] * n
		for i in range(n):
			xp[i] = li()
		zp = [0] * n
		for i in range(n):
			zp[i] = [0] * m
		for i in range(m):
			for j in range(n):
				if xp[j][i] == 1 and a[i] <= b[j]:
					zp[j][i] = a[i]
		for i in range(n):
			for j in range(m):
				if xp[i][j] == 1 and zp[i][j] == 0 and (b[i] <= a[j]):
					zp[i][j] = b[i]
		for i in range(n):
			print(*zp[i])
solve()


(a, b, c) = map(int, input().split())
mb = list(map(int, input().split()))
ma = list(map(int, input().split()))
mt = [list(map(int, input().split())) for i in range(a)]
rez = [[mb[i] for i in range(b)] for j in range(a)]
for i in range(a):
	for j in range(b):
		if rez[i][j] > ma[i]:
			rez[i][j] = ma[i]
for i in range(a):
	for j in range(b):
		if mt[i][j] == 0:
			rez[i][j] = 0
for i in range(a):
	print(' '.join(map(str, rez[i])))


(n, m, h) = map(int, input().split())
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
matrix = []
fig = [[-1] * m for i in range(n)]
for i in range(n):
	matrix.append([int(x) for x in input().split()])
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 0:
			fig[i][j] = 0
		else:
			fig[i][j] = min(left[i], front[j])
for i in range(n):
	print(*fig[i])


import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(n)]
ans = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if x[i][j] == 1:
			ans[i][j] = min(b[i], a[j])
for i in range(n):
	print(*ans[i])


(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()


(n, m, hh) = map(int, input().split())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
h = [[int(s) for s in input().split()] for i in range(n)]
result = [[j for j in a] for i in range(n)]
for i in range(n):
	for j in range(m):
		result[i][j] = min(result[i][j], b[i]) * h[i][j]
for s in result:
	print(' '.join([str(i) for i in s]))


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = []
for i in range(n):
	h.append(list(map(int, input().split())))
tmp = [0] * m
answer = h
for i in range(m):
	for j in range(n):
		if h[j][i] != 0 and b[j] >= a[i]:
			answer[j][i] = a[i]
for i in range(n):
	for j in range(m):
		if h[i][j] != 0 and b[i] <= a[j] and (max(answer[i]) != b[i]):
			answer[i][j] = b[i]
			break
for i in range(n):
	for j in range(m):
		print(str(answer[i][j]) + ' ')
	print('\n')


(N, M, H) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
t = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
	for j in range(M):
		if not t[i][j]:
			continue
		t[i][j] = min(B[i], A[j])
	print(' '.join(map(str, t[i])))


(n, m, h) = map(int, input().split())
listf = [0] * m
listl = [0] * n
listh = [[0] * m for i in range(n)]
listp = [[0] * m for i in range(n)]
listf = input().split()
listl = input().split()
for i in range(n):
	listh[i] = input().split()
for j in range(m):
	for i in range(n):
		if int(listh[i][j]):
			listp[i][j] = int(listf[j])
		else:
			listp[i][j] = 0
for i in range(n):
	for j in range(m):
		if int(listh[i][j]):
			listp[i][j] = min(listp[i][j], int(listl[i]))
cnt = 0
for i in range(n):
	for j in range(m):
		print(listp[i][j], ' ', end='')
		cnt = cnt + 1
		if cnt % m == 0:
			print('\n')


inputs = [int(x) for x in input().split()]
n = inputs[0]
m = inputs[1]
h = inputs[2]
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
top = []
for i in range(n):
	top.append([int(x) for x in input().split()])
for i in range(m):
	for j in range(n):
		if top[j][i] != 0:
			top[j][i] = min(front[i], left[j])
for i in range(n):
	for j in range(m - 1):
		print(top[i][j], end=' ')
	print(top[i][m - 1])


t = list(map(int, input().rstrip().split()))
k = list(map(int, input().rstrip().split()))
j = list(map(int, input().rstrip().split()))
matrix = []
for i in range(t[0]):
	matrix.append(list(map(int, input().rstrip().split())))
for v in range(t[0]):
	for g in range(t[1]):
		if matrix[v][g] == 0:
			matrix[v][g] = 0
		else:
			matrix[v][g] = min(j[v], k[g])
for q in range(t[0]):
	for d in range(t[1]):
		print(matrix[q][d], end=' ')
	print(' ')


def setup(x):
	if x == '0':
		return 0
	else:
		return '_'
(n, m, h) = map(int, input().strip().split())
front = list(map(int, input().strip().split()))
left = list(map(int, input().strip().split()))
matrix = []
holes = 0
transposed = 0
doneNothing = 0
for i in range(n):
	matrix.append(list(map(setup, input().strip().split())))
for (i, row) in enumerate(matrix):
	if row.count('_') == 1:
		j = row.index('_')
		matrix[i][j] = min(left[i], front[j])
	holes += row.count('_')
while holes > 0 and doneNothing < 2:
	doneSomething = False
	matrix = [list(x) for x in zip(*matrix)]
	transposed += 1
	for (i, row) in enumerate(matrix):
		if row.count('_') == 1:
			j = row.index('_')
			if transposed % 2 == 1:
				matrix[i][j] = min(front[i], left[j])
				doneSomething = True
				doneNothing = 0
			else:
				matrix[i][j] = min(left[i], front[j])
				doneSomething = True
				doneNothing = 0
			holes -= 1
	if not doneSomething:
		doneNothing += 1
if transposed % 2 == 1:
	matrix = [list(x) for x in zip(*matrix)]
for (i, row) in enumerate(matrix):
	for (j, col) in enumerate(row):
		if col == '_':
			matrix[i][j] = min(left[i], front[j])
			holes -= 1
		if holes == 0:
			break
	if holes == 0:
		break
for row in matrix:
	print(*row)


(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):
	temp = list(map(int, input().split()))
	top.append(temp)
for i in range(n):
	for j in range(m):
		if top[i][j] == 0:
			pass
		elif front[j] == left[i]:
			top[i][j] = front[j]
		elif front[j] < left[i]:
			top[i][j] = front[j]
		else:
			top[i][j] = left[i]
for i in range(n):
	print(*top[i])


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()


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

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

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

def input():
	return sys.stdin.readline().strip()
(n, m, h) = get_ints()
col_max = get_array()
row_max = get_array()
mat = []
for i in range(n):
	mat.append(get_array())
for i in range(m):
	maxi = col_max[i]
	for j in range(n):
		if mat[j][i] == 1:
			mat[j][i] = maxi
for i in range(n):
	maxi = row_max[i]
	for j in range(m):
		if mat[i][j] != 0:
			mat[i][j] = min(mat[i][j], maxi)
for i in range(n):
	print(*mat[i], sep=' ')


(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()


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, m, h) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
t = [[int(x) for x in input().split()] for i in range(n)]
for i in range(n):
	for j in range(m):
		if not t[i][j]:
			continue
		t[i][j] = min(b[i], a[j])
	print(*t[i])


nmh = input().split()
n = int(nmh[0])
m = int(nmh[1])
h = int(nmh[2])
front = [int(i) for i in input().split()]
left = [int(i) for i in input().split()]
top = []
for i in range(n):
	r = []
	r = [int(k) for k in input().split()]
	top.append(r)
for i in range(n):
	for j in range(m):
		if top[i][j] == 1:
			top[i][j] = min(front[j], left[i])
for i in range(n):
	print(*top[i])


(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, h) = list(map(int, input().split()))
front = [int(x) for x in input().split()]
left = [int(x) for x in input().split()]
top = [[int(x) for x in input().split()] for _ in range(n)]
box = [[[top[nn][mm]] * h for mm in range(m)] for nn in range(n)]
for j in range(m):
	for i in range(n):
		for z in range(front[j], h):
			box[i][j][z] = 0
for i in range(n):
	for j in range(m):
		for z in range(left[i], h):
			box[i][j][z] = 0
for i in range(n):
	print(' '.join((str(sum(box[i][j])) for j in range(m))))


(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('')


(n, m, h) = [int(i) for i in input().split()]
col = [int(i) for i in input().split()]
row = [int(i) for i in input().split()]
mat = [[int(i) for i in input().split()] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if mat[i][j] != 0:
			mat[i][j] = max(mat[i][j], min(row[i], col[j]))
print('\n'.join((' '.join((str(i) for i in line)) for line in mat)))


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)


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [list(map(int, input().split())) for y in range(n)]
u = [[0] * m for _ in range(n)]
for y in range(n):
	for x in range(m):
		u[y][x] = min(a[x], b[y]) * t[y][x]
print('\n'.join((' '.join(map(str, i)) for i in u)))


def inp():
	temp = list(map(int, input().split()))
	return temp

def main():
	(n, m, h) = map(int, input().split())
	front = inp()
	left = inp()
	top = []
	for i in range(n):
		temp = inp()
		top.append(temp)
	ans = [[0] * m for i in range(n)]
	for i in range(n):
		for j in range(m):
			if top[i][j]:
				ans[i][j] = min(front[j], left[i])
	for row in ans:
		print(*row)
main()


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = []
ans = [[0 for i in range(m)] for i in range(n)]
for i in range(n):
	h.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if h[i][j] == 1:
			ans[i][j] = min(a[j], b[i])
for i in ans:
	print(*i)


import math

def main():
	(n, m, h) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	grid = [[] for j in range(n)]
	for row in range(n):
		grid[row] = list(map(int, input().split()))
	for row in range(n):
		for col in range(m):
			if grid[row][col] == 1:
				grid[row][col] = min(a[col], b[row])
	for row in range(n):
		print(' '.join(map(str, grid[row])))
main()


(n, m, h) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(n)]
for i in range(n):
	for j in range(m):
		if s[i][j] == 1:
			s[i][j] = max(s[i][j], min(a[j], b[i]))
for i in s:
	print(*i)


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()


(dl, shir, vys) = map(int, input().split())
vid_sp = list(map(int, input().split()))
vid_sl = list(map(int, input().split()))
a = []
for i in range(dl):
	row = list(map(int, input().split()))
	a.append(row)
	stt = []
	for j in range(shir):
		if a[i][j] == 0:
			stt.append(0)
		else:
			stt.append(min(vid_sl[i], vid_sp[j]))
	print(*stt)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
(n, m, h) = rint()
fv = list(rint())
lv = list(rint())
tv = [[] for i in range(n)]
for i in range(n):
	tv[i] = list(rint())
for i in range(n):
	for j in range(m):
		if tv[i][j] == 0:
			continue
		tv[i][j] = fv[j]
for c in range(m):
	for r in range(n):
		if tv[r][c] > lv[r]:
			tv[r][c] = lv[r]
for i in range(n):
	print(*tv[i])


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('')


(l, w, h) = map(int, input().split())
fv = list(map(int, input().split()))
lv = list(map(int, input().split()))
tv = [list(map(int, input().split())) for i in range(l)]
for i in range(l):
	for j in range(w):
		if tv[i][j] == 1:
			tv[i][j] = min(fv[j], lv[i])
for i in tv:
	print(' '.join(map(str, i)))


import string, copy

def solution(a, b, matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[0])):
			if matrix[i][j]:
				matrix[i][j] = min(b[i], a[j])
	return matrix

def parser():
	(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(' ')]
	matrix = []
	for _ in range(n):
		matrix.append([int(i) for i in input().split(' ')])
	return (a, b, matrix)

def output(s):
	for row in s:
		print(' '.join((str(i) for i in row)))

def main():
	args = parser()
	result = solution(*args)
	output(result)
main()


(n, m, h) = map(int, input().split())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
v = [[*map(int, input().split())] for _ in range(n)]
res = [[v[i][j] * a[j] for j in range(m)] for i in range(n)]
(ma, mb) = (max(a), max(b))
l = [[] for _ in range(n)]
for i in range(n):
	if b[i] == ma:
		continue
	for j in range(m):
		if v[i][j] and b[i] < a[j]:
			res[i][j] = b[i]
for l in res:
	print(' '.join(map(str, l)))


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
(n, m, h) = get_ints()
front = get_ints()
left = get_ints()
top = [get_ints() for i in range(n)]
for i in range(n):
	for j in range(m):
		if top[i][j] == 1:
			top[i][j] = min(front[j], left[i])
for row in top:
	print(' '.join([str(x) for x in row]))


(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()


(n, m, h) = map(int, input().split())
Fr = list(map(int, input().split()))
Le = list(map(int, input().split()))
Ma = [list(map(int, input().split())) for _ in range(n)]
TL = [[-1] * m for _ in range(n)]
for i in range(m):
	for j in range(n):
		if Ma[j][i]:
			TL[j][i] = min(Fr[i], Le[j])
		else:
			TL[j][i] = 0
for t in TL:
	print(*t)


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 math
(n, m, h) = list(map(int, input().split()))
m_prof = list(map(int, input().split()))
n_prof = list(map(int, input().split()))
top_prof = [None] * n
res = [None] * n
for i in range(n):
	top_prof[i] = list(map(int, input().split()))
	res[i] = [0] * m

def get_height(i, j):
	nv = n_prof[i]
	mv = m_prof[j]
	return min(nv, mv)
for i in range(n):
	for j in range(m):
		if top_prof[i][j]:
			res[i][j] = get_height(i, j)
for row in res:
	print(' '.join((str(h) for h in row)))


import math
import collections
import bisect

def solve(n, m, h, a, b, grid):
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 1:
				grid[i][j] = min(a[j], b[i])
	return '\n'.join([' '.join([str(j) for j in grid[i]]) for i in range(n)])
(n, m, h) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
grid = [[int(s) for s in input().split()] for i in range(n)]
result = solve(n, m, h, a, b, grid)
print(result)


input()
Front = list(map(int, input().split()))
Left = list(map(int, input().split()))
X = []
for i in range(len(Left)):
	Temp = list(map(int, input().split()))
	X.append(Temp)
for i in range(len(Left)):
	for j in range(len(Front)):
		if X[i][j] == 1:
			X[i][j] = min(Left[i], Front[j])
for i in range(len(Left)):
	print(*X[i])


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()


import sys, collections
(n, m, h) = map(int, sys.stdin.readline().split())
front = list(map(int, sys.stdin.readline().split()))
left = list(map(int, sys.stdin.readline().split()))
top = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ans = [[0] * m for _ in range(n)]
for i in range(n):
	for j in range(m):
		ans[i][j] = top[i][j]
for i in range(n):
	for j in range(m):
		if ans[i][j]:
			if front[j] >= left[i]:
				ans[i][j] = left[i]
			else:
				ans[i][j] = front[j]
for i in ans:
	print(' '.join(map(str, i)))


[n, m, h] = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	row = ind[i]
	ans = m * [0]
	for j in range(m):
		if row[j] > 0:
			ans[j] = min(a[j], b[i])
	print(*ans)


(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())
lj = list(map(int, input().split()))
li = list(map(int, input().split()))
l = []
for i in range(n):
	lh = list(map(int, input().split()))
	for j in range(m):
		if lh[j] == 1:
			lh[j] = min(li[i], lj[j])
	l.append(lh)
for i in range(n):
	print(*l[i])


(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) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	k = [0] * m
	l = list(map(int, input().split()))
	for y in range(m):
		if l[y] != 0:
			k[y] = min(b[i], a[y])
	print(*k)


(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
sys_input = sys.stdin.readline

def si():
	return sys_input().rstrip()

def ii():
	return int(si())

def sti():
	return si().split()

def iti():
	return map(int, sti())

def sli():
	return list(si())

def ili():
	return list(iti())
(n, m, h) = iti()
a = ili()
b = ili()
c = [ili() for i in range(n)]
for y in range(n):
	for x in range(m):
		if c[y][x] == 0:
			continue
		c[y][x] = min([a[x], b[y]])
	print(' '.join([str(i) for i in c[y]]))


_DEBUG = True
(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
top_view = [list(map(int, input().split())) for _ in range(n)]
top_confirmed = [[True] * m for _ in range(n)]
block_count = 0
for i in range(n):
	for j in range(m):
		if top_view[i][j] == 1:
			top_view[i][j] = min(a[j], b[i])
for i in range(n):
	print(' '.join(map(str, top_view[i])))


(n, m, h) = list(map(int, input().split()))
maks_kol = list(map(int, input().split()))
maks_wie = list(map(int, input().split()))
gora = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if gora[i][j] == 1:
			gora[i][j] = min(maks_wie[i], maks_kol[j])
for j in range(n):
	for i in range(m):
		if i < m - 1:
			print(gora[j][i], end=' ')
		else:
			print(gora[j][i], end='\n')


while True:
	try:
		(n, m, h) = map(int, input().strip().split())
		f = list(map(int, input().strip().split()))
		l = list(map(int, input().strip().split()))
		t = [list(map(int, input().strip().split())) for _ in range(n)]
		for j in range(n):
			for k in range(m):
				if t[j][k] and f[k] > t[j][k]:
					t[j][k] = min(f[k], l[j])
		for r in range(n):
			print(' '.join(map(str, t[r])))
	except:
		break


(n, m, h) = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
x = []
for _ in range(n):
	x.append([int(v) for v in input().split()])
ans = []
for r in x:
	ans.append(r.copy())
for ai in range(len(a)):
	if a[ai] <= 1:
		continue
	for bi in range(len(b)):
		if a[ai] <= b[bi] and x[bi][ai] == 1:
			ans[bi][ai] = a[ai]
for bi in range(len(b)):
	if b[bi] <= 1:
		continue
	for ai in range(len(a)):
		if ans[bi][ai] < b[bi] <= a[ai] and x[bi][ai] == 1:
			ans[bi][ai] = b[bi]
for r in ans:
	print(' '.join([str(v) for v in r]))


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) = [int(i) for i in input().split(' ')]
front = [int(i) for i in input().split(' ')]
left = [int(i) for i in input().split(' ')]
top = []
for i in range(n):
	top.append([int(i) for i in input().split(' ')])
res = [[i for i in lst] for lst in top]
for i in range(n):
	for j in range(m):
		if res[i][j]:
			res[i][j] = min(front[j], left[i])
for i in range(n):
	print(' '.join((str(j) for j in res[i])))


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = []
for i in range(n):
	z = list(map(int, input().split()))
	t.append(z)
for i in range(n):
	for j in range(m):
		if t[i][j] != 0:
			t[i][j] = min(a[j], b[i])
for i in range(n):
	print(*t[i])


import sys
read = sys.stdin.readline
(n, m, h) = list(map(int, read().split()))
front = list(map(int, read().split()))
left = list(map(int, read().split()))
top = [[-1 for _ in range(m)] for _ in range(n)]
for i in range(n):
	top[i] = list(map(int, read().split()))
block_map = [[-1 for _ in range(m)] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if top[i][j] == 0:
			block_map[i][j] = 0
		else:
			block_map[i][j] = min(left[i], front[j])
for i in range(n):
	buffer = ''
	for j in range(m):
		buffer += str(block_map[i][j]) + ' '
	print(buffer.rstrip())


(n, m, h) = map(int, input().split())
a = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
d = []
for i in range(n):
	d.append([int(i) for i in input().split()])
for i in range(n):
	for j in range(m):
		if d[i][j] == 1:
			d[i][j] = min(a[j], s[i])
for i in range(n):
	print(*d[i])


(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('')


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


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) = [int(x) for x in input().split()]
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
c = []
for case in range(n):
	c.append([int(x) for x in input().split()])
for i in range(n):
	for j in range(m):
		if c[i][j] == 1:
			c[i][j] = l1[j]
for i in range(n):
	for j in range(m):
		if c[i][j] > l2[i]:
			c[i][j] = l2[i]
for i in range(n):
	for j in range(m):
		print(c[i][j], end=' ')


gi = lambda : list(map(int, input().strip().split()))
(n, m, h) = gi()
c = gi()
l = gi()
ans = [gi() for e in range(n)]
for k in range(n):
	for j in range(m):
		if c[j] <= l[k] and ans[k][j]:
			ans[k][j] = c[j]
		elif l[k] <= c[j] and ans[k][j]:
			ans[k][j] = l[k]
print('\n'.join([' '.join(map(str, e)) for e in ans]))


import sys
import math, collections
input = sys.stdin.readline

def pr(*args, **kwargs):
	print(*args, **{'end': '', **kwargs})

def prln(*args, **kwargs):
	print(*args, **kwargs)

def fill(arr, val):
	for i in range(len(arr)):
		if isinstance(arr[i], list):
			fill(arr[i], val)
		else:
			arr[i] = val

def ls(*dims):
	if len(dims) == 0:
		return []
	a = dims[::-1]
	res = [0] * a[0]
	for i in a[1:]:
		res = [res.copy() for _ in range(i)]
	return res
rowin = lambda : list(map(int, input().split()))
numin = lambda : int(input())
(n, m, h) = rowin()
front = rowin()
left = rowin()
a = []
for i in range(n):
	x = rowin()
	a.append(x)
res = ls(n, m)
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			res[i][j] = min(front[j], left[i])
for l in res:
	print(*l)


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [[0] * m for _ in range(n)]
t = []
for i in range(n):
	t.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if t[i][j] == 1:
			t[i][j] = min(a[j], b[i])
for i in range(n):
	print(*t[i])


from sys import stdin
input = stdin.readline
(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
for i in range(n):
	x.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if x[i][j]:
			x[i][j] = min(a[j], b[i])
for i in x:
	print(*i)


from math import ceil
import sys
input = sys.stdin.readline
from collections import defaultdict as dd
(n, m, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
ll = []
for i in range(n):
	l = list(map(int, input().split()))
	ll.append(l)
for i in range(m):
	for j in range(n - 1, -1, -1):
		if ll[j][i] and left[j] >= front[i]:
			ll[j][i] = front[i]
for i in range(n):
	for j in range(m - 1, -1, -1):
		if ll[i][j] and front[j] >= left[i]:
			ll[i][j] = left[i]
			break
for i in ll:
	print(*i)


(n, m, h) = map(int, input().split())
sol = [[h for _ in range(m)] for _ in range(n)]
frente = list(map(int, input().split()))
lado = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		sol[i][j] = min(sol[i][j], frente[j])
for j in range(m):
	for i in range(n):
		sol[i][j] = min(sol[i][j], lado[i])
for i in range(n):
	top = list(map(int, input().split()))
	for j in range(m):
		if top[j] == 0:
			sol[i][j] = 0
for l in sol:
	print(' '.join((str(x) for x in l)))


(n, mi, h) = map(int, input().split())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
m = [list(map(int, input().split())) for _ in range(n)]
for row in range(n):
	for col in range(mi):
		if m[row][col]:
			m[row][col] = min(front[col], left[row])
for l in m:
	print(' '.join((str(x) for x in l)))


(n, m, h) = map(int, input().split())
shape = [0] * n
front = list(map(int, input().split()))
left = list(map(int, input().split()))
for i in range(n):
	shape[i] = [v * h for v in map(int, input().split())]
for j in range(m):
	for i in range(n):
		shape[i][j] = min(shape[i][j], front[j])
for i in range(n):
	for j in range(m):
		shape[i][j] = min(shape[i][j], left[i])
for i in range(n):
	print(' '.join([str(v) for v in shape[i]]))


(N, M, H) = [int(s) for s in input().split()]
front = [int(s) for s in input().split()]
left = [int(s) for s in input().split()]
top = []
for i in range(N):
	top.append([int(s) for s in input().split()])
for i in range(N):
	for j in range(M):
		if top[i][j] == 1:
			top[i][j] = min(front[j], left[i])
for i in range(N):
	print(' '.join([str(h) for h in top[i]]))


(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())
front = list(map(int, input().split()))
left = list(map(int, input().split()))
top = [list(map(int, input().split())) for i in range(n)]
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if top[i][j] == 0:
			ans[i][j] = 0
		else:
			ans[i][j] = min(front[j], left[i])
for i in range(n):
	print(' '.join([str(ans[i][j]) for j in range(m)]))


(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()


def mat(a):
	for x in a:
		print(*x)
(n, m, h) = map(int, input().split())
front = [int(j) for j in input().split()]
side = [int(j) for j in input().split()]
top = [[int(j) for j in input().split()] for k in range(n)]
for y in range(m):
	for z in range(n):
		if top[z][y] == 1:
			top[z][y] = front[y]
for x in range(n):
	ori = side[x]
	for y in range(m):
		if top[x][y] > ori:
			top[x][y] = ori
mat(top)


(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()


(n, m, h) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ms = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	if b[i] > 1:
		for j in range(m):
			if a[j] == b[i] and ms[i][j] != 0 or (ms[i][j] == 1 and a[j] > b[i]):
				ms[i][j] = b[i]
for i in range(m):
	if a[i] > 1:
		for j in range(n):
			if a[i] == b[j] and ms[j][i] != 0 or (ms[j][i] == 1 and a[i] < b[j]):
				ms[j][i] = a[i]
for i in ms:
	print(*i)


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()


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


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')


import sys
input = sys.stdin.readline

def main():
	(n, m, h) = map(int, input().split())
	front = list(map(int, input().split()))
	left = list(map(int, input().split()))
	top = [list(map(int, input().split())) for _ in range(n)]
	r = [['0'] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if top[i][j]:
				r[i][j] = str(min(left[i], front[j]))
	print('\n'.join((' '.join(r[i]) for i in range(n))))
main()


(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()