Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.

Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.

Your program has to support two operations:   Paint all cells in row r_{i} in color a_{i};  Paint all cells in column c_{i} in color a_{i}. 

If during some operation i there is a cell that have already been painted, the color of this cell also changes to a_{i}.

Your program has to print the resulting table after k operation.


-----Input-----

The first line of the input contains three integers n, m and k (1  ≤  n,  m  ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.

Each of the next k lines contains the description of exactly one query:   1 r_{i} a_{i} (1 ≤ r_{i} ≤ n, 1 ≤ a_{i} ≤ 10^9), means that row r_{i} is painted in color a_{i};  2 c_{i} a_{i} (1 ≤ c_{i} ≤ m, 1 ≤ a_{i} ≤ 10^9), means that column c_{i} is painted in color a_{i}. 


-----Output-----

Print n lines containing m integers each — the resulting table after all operations are applied.


-----Examples-----
Input
3 3 3
1 1 3
2 2 1
1 2 2

Output
3 1 3 
2 2 2 
0 1 0 

Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1

Output
1 1 1 
1 0 1 
1 1 1 
1 0 1 
1 1 1 



-----Note-----

The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.  [Image]

Difficulty: EASY
Tags: Implementation

Constructive algorithms

Starter code:

Solutions:
def process_input():
	(n, m, k) = map(int, input().split())
	rows = {}
	cols = {}
	for p in range(1, k + 1):
		(o, i, a) = input().split()
		if o == '1':
			rows[int(i)] = (a, p)
		else:
			cols[int(i)] = (a, p)
	return (n, m, rows, cols)

def generate_output(n, m, rows, cols):
	for r in range(1, n + 1):
		(ra, rp) = rows[r] if r in rows else ('0', 0)
		row = []
		for c in range(1, m + 1):
			(ca, cp) = cols[c] if c in cols else ('0', 0)
			row.append(ca if cp > rp else ra)
		print(' '.join(row))
(n, m, rows, cols) = process_input()
generate_output(n, m, rows, cols)


(n, m, k) = map(int, input().split())
instanteLinhas = [0] * n
instanteColunas = [0] * m
cores = [0] * (k + 1)
for i in range(k):
	(op, lc, cor) = input().split()
	lc = int(lc)
	cor = int(cor)
	cores[i + 1] = cor
	if op == '1':
		instanteLinhas[lc - 1] = i + 1
	elif op == '2':
		instanteColunas[lc - 1] = i + 1
resp = ''
for i in range(n):
	for j in range(m):
		resp += str(cores[max(instanteLinhas[i], instanteColunas[j])])
		if j != m - 1:
			resp += ' '
	if i != n - 1:
		resp += '\n'
print(resp)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
(n, m, k) = map(int, input().split())
row = [(0, 0)] * n
col = [(0, 0)] * m
for i in range(k):
	(t, rc, a) = map(int, input().split())
	rc -= 1
	if t == 1:
		row[rc] = (i, a)
	else:
		col[rc] = (i, a)
for i in range(n):
	for j in range(m):
		upd = max(row[i], col[j])
		if upd == (0, 0):
			print(0, end=' ')
		else:
			print(upd[1], end=' ')
	print()


read = lambda : map(int, input().split())
(n, m, k) = read()
mat = [[0] * m for i in range(n)]
row = [(0, -1)] * n
col = [(0, -1)] * m
for i in range(k):
	(a, b, c) = read()
	if a == 1:
		row[b - 1] = (c, i)
	else:
		col[b - 1] = (c, i)
for i in range(n):
	for j in range(m):
		if row[i][1] > col[j][1]:
			mat[i][j] = row[i][0]
		else:
			mat[i][j] = col[j][0]
for i in mat:
	print(*i)


(n, m, k) = map(int, input().split())
rowclr = [[-1, -1]] * n
colclr = [[-1, -1]] * m
oprt = {}
mat = [[0 for j in range(m)] for i in range(n)]
for i in range(k):
	(a, b, c) = map(int, input().split())
	oprt[b - 1, a] = [i, c]
d = {k: oprt[k] for k in sorted(oprt, key=oprt.get)}
for (k, v) in d.items():
	if k[1] == 1:
		row = k[0]
		add = v[1]
		for j in range(m):
			mat[row][j] = add
	else:
		col = k[0]
		add = v[1]
		for i in range(n):
			mat[i][col] = add
for i in range(n):
	print(*mat[i])


(n, m, k) = [int(x) for x in input().split(' ')]
rows = [[0, -1]] * n
cols = [[0, -1]] * m
for i in range(k):
	tmp = [int(x) for x in input().split(' ')]
	if tmp[0] == 1:
		rows[tmp[1] - 1] = [tmp[2], i]
	else:
		cols[tmp[1] - 1] = [tmp[2], i]
for i in range(n):
	for j in range(m):
		print(rows[i][0] if rows[i][1] > cols[j][1] else cols[j][0], end=' ')
	print()


def fill_column(num, color):
	nonlocal canvas
	for i in range(n):
		canvas[i][num] = color

def fill_row(num, color):
	nonlocal canvas
	for i in range(m):
		canvas[num][i] = color
(n, m, k) = map(int, input().split())
canvas = [[0 for j in range(m)] for i in range(n)]
(T, num, color) = (0, 0, 0)
a = []
T1 = [-1 for i in range(n)]
T2 = [-1 for j in range(m)]
for i in range(k):
	(T, num, color) = map(int, input().split())
	a.append((T, num - 1, color))
	if T == 1:
		T1[num - 1] = i
	else:
		T2[num - 1] = i
for i in range(k):
	if a[i][0] == 1:
		if T1[a[i][1]] == i:
			fill_row(a[i][1], a[i][2])
	elif T2[a[i][1]] == i:
		fill_column(a[i][1], a[i][2])
for i in range(n):
	for j in range(m):
		print(canvas[i][j], end=' ')
	print()


import atexit
import io
import sys
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
(n, m, k) = map(int, input().split())
n += 1
m += 1
grid = [[0] * m for i in range(n)]
row = [0] * n
col = [0] * m
inps = []
for i in range(k):
	inps.append(tuple(map(int, input().split())))
box = 0
for i in range(k - 1, -1, -1):
	if box == (n - 1) * (m - 1):
		break
	if inps[i][0] == 1:
		r = inps[i][1]
		if row[r] == 0:
			row[r] = inps[i][2]
			for j in range(1, m):
				if grid[r][j] == 0:
					grid[r][j] = inps[i][2]
					box += 1
	else:
		r = inps[i][1]
		if col[r] == 0:
			col[r] = inps[i][2]
			for j in range(1, n):
				if grid[j][r] == 0:
					grid[j][r] = inps[i][2]
					box += 1
for i in range(1, n):
	for j in range(1, m):
		print(grid[i][j], end=' ')
	print()


(n, m, k) = map(int, input().split())
row_color = [0] * n
row_time = [0] * n
col_color = [0] * m
col_time = [0] * m
for i in range(k):
	(cmd, idx, color) = map(int, input().split())
	idx -= 1
	if cmd == 1:
		row_color[idx] = color
		row_time[idx] = i + 1
	else:
		col_color[idx] = color
		col_time[idx] = i + 1
for i in range(n):
	for j in range(m):
		if row_time[i] > col_time[j]:
			print(row_color[i], end=' ')
		else:
			print(col_color[j], end=' ')
	print()


from sys import stdin, stdout

def main():
	(n, m, k) = map(int, stdin.readline().strip().split(' '))
	r = [0] * n
	c = [0] * m
	a = [0] * (k + 1)
	for i in range(1, k + 1):
		(l, xi, a[i]) = map(int, stdin.readline().strip().split(' '))
		if l == 1:
			r[xi - 1] = i
		else:
			c[xi - 1] = i
	for i in range(n):
		l = []
		for j in range(m):
			l.append(str(a[max(r[i], c[j])]))
		print(' '.join(l))
main()


(n, m, k) = map(int, input().split(' '))
row = [(0, -1)] * 5010
col = [(0, -1)] * 5010
for i in range(1, k + 1):
	(a, b, c) = map(int, input().split(' '))
	if a == 1:
		row[b] = (c, i)
	else:
		col[b] = (c, i)
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if row[i][1] > col[j][1]:
			print(row[i][0], end=' ')
		else:
			print(col[j][0], end=' ')
	print()


def main():
	from sys import stdin, stdout
	(n, m, op) = list(map(int, stdin.readline().split()))
	hor = dict()
	vert = dict()
	for i in range(op):
		(a, b, c) = list(map(int, input().split()))
		b -= 1
		if a == 1:
			hor[b] = (c, i)
		else:
			vert[b] = (c, i)
	for i in range(n):
		for j in range(m):
			if i not in hor:
				hor[i] = (0, -1)
			if j not in vert:
				vert[j] = (0, -1)
			if hor[i][1] > vert[j][1]:
				stdout.write(str(hor[i][0]) + ' ')
			else:
				stdout.write(str(vert[j][0]) + ' ')
		stdout.write('\n')
main()


(n, m, k) = map(int, input().split(' '))
mat = []
for i in range(n + 1):
	mat.append([0] * (m + 1))
check = []
for i in range(2):
	check.append([False] * 5001)
l = []
for i in range(k):
	l.append(list(map(int, input().split(' '))))
for i in range(k - 1, -1, -1):
	if not check[l[i][0] - 1][l[i][1]]:
		if l[i][0] == 1:
			for j in range(1, m + 1):
				if mat[l[i][1]][j] == 0:
					mat[l[i][1]][j] = l[i][2]
		else:
			for j in range(1, n + 1):
				if mat[j][l[i][1]] == 0:
					mat[j][l[i][1]] = l[i][2]
		check[l[i][0] - 1][l[i][1]] = True
for i in range(1, n + 1):
	for j in range(1, m + 1):
		print(mat[i][j], end=' ')
	print('')


import atexit, io, sys, functools
buffer = io.StringIO()
sys.stdout = buffer

@atexit.register
def write():
	sys.__stdout__.write(buffer.getvalue())

@functools.lru_cache(maxsize=1024)
def main():
	(n, m, k) = map(int, sys.stdin.readline().rstrip().split())
	B1 = [[0, 0, 0, 0] for i in range(n)]
	B2 = [[0, 0, 0, 0] for i in range(m)]
	for i in range(k):
		(a, b, c) = map(int, sys.stdin.readline().rstrip().split())
		b -= 1
		if a == 1:
			B1[b] = [i, a, b, c]
		else:
			B2[b] = [i, a, b, c]
	C = sorted(B1 + B2, key=lambda x: x[0])
	A = [[0] * m for i in range(n)]
	for i in range(len(C)):
		(x, a, b, c) = C[i]
		if a == 1:
			A[b] = [c] * m
		elif a == 2:
			for j in range(n):
				A[j][b] = c
	for row in A:
		sys.stdout.write(' '.join(map(str, row)) + '\n')
main()


import sys
(n, m, k) = [int(x) for x in input().split()]
(L, C) = ([(-1, 0) for i in range(n)], [(-1, 0) for i in range(m)])
for (i, line) in enumerate(sys.stdin):
	(t, r, c) = [int(x) for x in line.split()]
	if t == 1:
		L[r - 1] = (i, c)
	else:
		C[r - 1] = (i, c)
matrix = [[max(L[i], C[j])[1] for j in range(m)] for i in range(n)]
for i in range(n):
	sys.stdout.write(' '.join(map(str, matrix[i])) + '\n')


(n, m, k) = map(int, input().split())
rows = [[0, 0] for i in range(n)]
cols = [[0, 0] for i in range(m)]
for i in range(k):
	(typ, p, x) = map(int, input().split())
	if typ == 1:
		rows[p - 1] = [x, i + 1]
	elif typ == 2:
		cols[p - 1] = [x, i + 1]
	else:
		print('WTF?!')
for i in range(n):
	line = []
	for j in range(m):
		if rows[i][1] > cols[j][1]:
			line.append(rows[i][0])
		else:
			line.append(cols[j][0])
	print(' '.join(map(str, line)))


import random

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

def lcm(a, b):
	return a * b / gcd(a, b)
(n, m, k) = map(int, input().split())
r = [[0, 0] for i in range(n)]
c = [[0, 0] for i in range(m)]
for _ in range(k):
	(x, w, v) = map(int, input().split())
	if x == 1:
		r[w - 1][0] = _ + 1
		r[w - 1][1] = v
	else:
		c[w - 1][0] = _ + 1
		c[w - 1][1] = v
for i in range(n):
	for j in range(m):
		if r[i][0] >= c[j][0]:
			print(r[i][1], end=' ')
		else:
			print(c[j][1], end=' ')
	print('')


(n, m, k) = map(int, input().split())
row = [(0, 0)] * n
col = [(0, 0)] * m
for i in range(k):
	(x, r, a) = map(int, input().split())
	if x == 1:
		row[r - 1] = (i + 1, a)
	else:
		col[r - 1] = (i + 1, a)
ary = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if col[j][0] > row[i][0]:
			ary[i][j] = col[j][1]
		else:
			ary[i][j] = row[i][1]
for i in range(n):
	iar = map(str, ary[i])
	print(' '.join(iar))


def getnums():
	raw = input()
	raw = raw.split()
	return [int(num) for num in raw]
(n, m, k) = getnums()
a = [[0 for j in range(m + 1)] for i in range(n + 1)]
r = [False for i in range(n + 1)]
c = [False for j in range(m + 1)]
info = [getnums() for i in range(k)]

def draw(t, num, col):
	if t == 1:
		for i in range(1, m + 1):
			if a[num][i] == 0:
				a[num][i] = col
	else:
		for i in range(1, n + 1):
			if a[i][num] == 0:
				a[i][num] = col
i = k - 1
while i >= 0:
	if info[i][0] == 1:
		val = info[i][1]
		if not r[val]:
			r[val] = True
			draw(1, val, info[i][2])
	else:
		val = info[i][1]
		if not c[val]:
			c[val] = True
			draw(2, val, info[i][2])
	i = i - 1
for i in range(1, n + 1):
	for j in range(1, m):
		print(a[i][j], end=' ')
	print(a[i][m])


from sys import stdin

def main():
	(n, m, q) = map(int, stdin.readline().split())
	rid = [-1] * n
	rc = [-1] * n
	cid = [-1] * m
	cc = [-1] * m
	for i in range(q):
		(t, x, y) = map(int, stdin.readline().split())
		if t == 1:
			rid[x - 1] = i
			rc[x - 1] = y - 1
		else:
			cid[x - 1] = i
			cc[x - 1] = y - 1
	ans = [[0 for _ in range(m)] for _ in range(n)]
	query = []
	for i in range(n):
		query.append((rid[i], rc[i], i))
	for i in range(m):
		query.append((cid[i], cc[i], n + i))
	query.sort()
	for i in range(len(query)):
		(idx, c, t) = query[i]
		if c == -1:
			continue
		if t < n:
			for j in range(m):
				ans[t][j] = c + 1
		else:
			for j in range(n):
				ans[j][t - n] = c + 1
	for row in ans:
		print(*row)
main()


def main():
	from sys import stdin
	(n, m, k) = map(int, input().split())
	aa = [[0] * m for _ in range(n)]
	avail = (None, [True] * n, [True] * m)
	for s in reversed(stdin.read().splitlines()):
		(f, x, a) = map(int, s.split())
		av = avail[f]
		x -= 1
		if av[x]:
			av[x] = False
			if f == 1:
				row = aa[x]
				for (i, b) in enumerate(row):
					if not b:
						row[i] = a
			else:
				for row in aa:
					if not row[x]:
						row[x] = a
	print('\n'.join((' '.join(map(str, row)) for row in aa)))
main()


import sys
(n, m, k) = map(int, sys.stdin.readline().split())
rows = [[] for i in range(n)]
cols = [[] for i in range(m)]
for i in range(k):
	(command, num, color) = map(int, sys.stdin.readline().split())
	num = num - 1
	if command == 1:
		rows[num].append((i, color))
	else:
		cols[num].append((i, color))
for i in range(n):
	for j in range(m):
		color = 0
		if len(cols[j]) > 0:
			if len(rows[i]) > 0:
				if cols[j][-1][0] > rows[i][-1][0]:
					color = cols[j][-1][1]
				else:
					color = rows[i][-1][1]
			else:
				color = cols[j][-1][1]
		elif len(rows[i]) > 0:
			color = rows[i][-1][1]
		sys.stdout.write(str(color))
		if j + 1 < m:
			sys.stdout.write(' ')
		else:
			sys.stdout.write('\n')


(n, m, k) = map(int, input().split())
lst_lines = [0 for i in range(max(n, m))]
lst_columns = [0 for i in range(max(n, m))]
matrix = []
for i in range(n):
	matrix.append([0 for i in range(m)])
for time in range(k):
	(str_or_col, index, color) = map(int, input().split())
	if str_or_col == 1:
		lst_lines[index - 1] = (color, time)
	else:
		lst_columns[index - 1] = (color, time)
for line in range(n):
	if lst_lines[line] != 0:
		lst_line_color = lst_lines[line][0]
		lst_line_time = lst_lines[line][1]
	else:
		lst_line_color = 0
		lst_line_time = -1
	for column in range(m):
		if lst_columns[column] != 0:
			lst_column_color = lst_columns[column][0]
			lst_column_time = lst_columns[column][1]
			if lst_column_time > lst_line_time:
				matrix[line][column] = lst_column_color
			else:
				matrix[line][column] = lst_line_color
		else:
			matrix[line][column] = lst_line_color
for line in matrix:
	print(' '.join(list(map(str, line))))


INP = lambda : list(map(int, input().split()))
(n, m, k) = INP()
instructions = {}
A = [[0 for i in range(m)] for j in range(n)]
for i in range(k):
	inp = INP()
	key = (inp[0], inp[1])
	val = [i, inp[2]]
	instructions[key] = val
for item in sorted(list(instructions.items()), key=lambda item: item[1][0]):
	key = item[0]
	val = item[1]
	if key[0] == 1:
		A[key[1] - 1] = [val[1] for i in range(m)]
	else:
		for j in range(n):
			A[j][key[1] - 1] = val[1]
for row in A:
	print(' '.join(map(str, row)))


def main():
	(n, m, k) = map(int, input().split())
	lst = [[0] * m for _ in range(n)]
	rows = {}
	cols = {}
	for i in range(k):
		(q, idx, a) = map(int, input().split())
		if q == 1:
			rows[idx - 1] = (a, i)
		else:
			cols[idx - 1] = (a, i)
	for r in range(n):
		for c in range(m):
			if r in rows and c in cols:
				if rows[r][1] > cols[c][1]:
					lst[r][c] = rows[r][0]
				else:
					lst[r][c] = cols[c][0]
			elif r in rows and c not in cols:
				lst[r][c] = rows[r][0]
			elif r not in rows and c in cols:
				lst[r][c] = cols[c][0]
	for e in lst:
		print(*e)
main()


(n, m, k) = map(int, input().split())
R = [[(0, 0)] * 2 for i in range(max(n, m))]
for x in range(k):
	(t, r, v) = map(int, input().split())
	R[r - 1][t - 1] = (x, v)
for i in range(n):
	for j in range(m):
		print(max(R[i][0], R[j][1])[1], end=' ')
	print()


from sys import *
input = stdin.readline
(n, m, k) = map(int, input().split())
l = []
r = [0] * n
c = [0] * m
rt = [0] * n
ct = [0] * m
for i in range(k):
	(z, x, y) = map(int, input().split())
	if z == 1:
		r[x - 1] = y
		rt[x - 1] = i + 1
	else:
		c[x - 1] = y
		ct[x - 1] = i + 1
for i in range(n):
	for j in range(m):
		if r[i] == c[j]:
			print(r[i], end=' ')
		elif rt[i] > ct[j]:
			print(r[i], end=' ')
		else:
			print(c[j], end=' ')
	print('')


b = list(map(int, input().split()))
a = [0] * 5002
c = [0] * 5002
d = [0] * 5002
e = [0] * 5002
for i in range(1, b[2] + 1):
	n = list(map(int, input().split()))
	if n[0] == 1:
		a[n[1]] = n[2]
		e[n[1]] = i
	else:
		c[n[1]] = n[2]
		d[n[1]] = i
for i in range(1, b[0] + 1):
	for j in range(1, b[1] + 1):
		if e[i] > d[j]:
			print(a[i], end=' ')
		else:
			print(c[j], end=' ')
	print('')


(n, m, k) = map(int, input().split())
rsv = [0 for _ in range(n)]
rsi = [-1 for _ in range(n)]
csv = [0 for _ in range(m)]
csi = [-1 for _ in range(m)]
for i in range(k):
	(t, j, a) = map(int, input().split())
	j -= 1
	if t == 1:
		rsv[j] = a
		rsi[j] = i
	else:
		csv[j] = a
		csi[j] = i
for i in range(n):
	for j in range(m):
		if rsi[i] > csi[j]:
			print(rsv[i], end=' ')
		else:
			print(csv[j], end=' ')
	print('')


(a, b, c) = map(int, input().split())
row = [0] * (a + 1)
col = [0] * (b + 1)
matrix = []
for i in ' ' * (a + 1):
	matrix += [[0] * (b + 1)]
z = []
for _ in ' ' * c:
	z += [list(map(int, input().split()))]
z = z[::-1]
for i in z:
	if i[0] == 1:
		if row[i[1]] == 0:
			row[i[1]] = 1
			for j in range(1, b + 1):
				if col[j] == 0:
					matrix[i[1]][j] = i[2]
	elif col[i[1]] == 0:
		col[i[1]] = 1
		for j in range(1, a + 1):
			if row[j] == 0:
				matrix[j][i[1]] = i[2]
for i in range(1, a + 1):
	print(*matrix[i][1:])


from functools import lru_cache
from sys import stdin, stdout

@lru_cache(maxsize=1024)
def main():
	(n, m, k) = map(int, stdin.readline().rstrip().split())
	B1 = [[0, 0, 0, 0] for i in range(n)]
	B2 = [[0, 0, 0, 0] for i in range(m)]
	for i in range(k):
		(a, b, c) = map(int, stdin.readline().rstrip().split())
		b -= 1
		if a == 1:
			B1[b] = [i, a, b, c]
		else:
			B2[b] = [i, a, b, c]
	C = sorted(B1 + B2, key=lambda x: x[0])
	A = [[0] * m for i in range(n)]
	for i in range(len(C)):
		(x, a, b, c) = C[i]
		if a == 1:
			A[b] = [c] * m
		elif a == 2:
			for j in range(n):
				A[j][b] = c
	for row in A:
		stdout.write(' '.join(map(str, row)) + '\n')
main()


def read_ints():
	return list(map(int, input().split()))
(nRows, nCols, nRqs) = read_ints()
rowTasks = {}
colTasks = {}
for i in range(nRqs):
	task = {}
	(task['op'], task['ind'], task['clr']) = read_ints()
	task['ind'] -= 1
	task['number'] = i
	if task['op'] == 1:
		rowTasks[task['ind']] = task
	else:
		colTasks[task['ind']] = task
for i in range(nRows):
	for j in range(nCols):
		clr = 0
		rowTask = None
		if i in rowTasks:
			rowTask = rowTasks[i]
			clr = rowTask['clr']
		if j in colTasks:
			colTask = colTasks[j]
			if rowTask == None or colTask['number'] > rowTask['number']:
				clr = colTask['clr']
		print(str(clr), end=' ')
	print('')


import sys
input = lambda : sys.stdin.readline().strip()
(n, m, k) = map(int, input().split())
row = [(-1, 0)] * n
col = [(-1, 0)] * m
for i in range(k):
	(a, b, c) = map(int, input().split())
	if a == 1:
		row[b - 1] = (i, c)
	else:
		col[b - 1] = (i, c)
for i in range(n):
	for j in range(m):
		if row[i][0] > col[j][0]:
			sys.stdout.write(str(row[i][1]))
		else:
			sys.stdout.write(str(col[j][1]))
		sys.stdout.write(' ')
	sys.stdout.write('\n')


(n, m, q) = list(map(int, input().split()))
(timeR, timeC, color) = ([0] * n, [0] * m, [0] * (q + 1))
for query in range(1, q + 1):
	(typeQ, posQ, color[query]) = list(map(int, input().split()))
	if typeQ == 1:
		timeR[posQ - 1] = query
	else:
		timeC[posQ - 1] = query
for i in range(n):
	out = str()
	for j in range(m):
		out += str(color[max(timeR[i], timeC[j])])
		out += ' '
	print(out)


(n, m, k) = map(int, input().split())
maxi = max(n, m)
(rows, cols) = ([], [])
for i in range(maxi + 1):
	rows.append((0, 0))
	cols.append((0, 0))
for i in range(1, k + 1):
	(x, y, c) = map(int, input().split())
	if x == 1:
		rows[y] = (i, c)
	else:
		cols[y] = (i, c)
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if cols[j][0] < rows[i][0]:
			print(rows[i][1], end=' ')
		else:
			print(cols[j][1], end=' ')
	print('')


(n, m, k) = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(k)]
T = [[0 for _ in range(m)] for _ in range(n)]
R = [[0, -1] for _ in range(n)]
C = [[0, -1] for _ in range(m)]
for i in range(k):
	q = Q[i]
	if q[0] == 1:
		R[q[1] - 1] = [q[2], i]
	else:
		C[q[1] - 1] = [q[2], i]
for i in range(n):
	for j in range(m):
		if R[i][1] > C[j][1]:
			T[i][j] = R[i][0]
		else:
			T[i][j] = C[j][0]
for i in range(n):
	for j in range(m):
		print(T[i][j], end=' ')
	print()


(n, m, k) = map(int, input().split())
dp = [[0 for ti in range(m)] for tj in range(n)]
d = {}
l = []
idx = {}
for t in range(k):
	(rc, nm, cl) = map(int, input().split())
	d[rc, nm] = cl
	if (rc, nm) in idx:
		l[idx[rc, nm]] = [-1, -1]
	l.append([rc, nm])
	idx[rc, nm] = len(l) - 1
q = []
for t in l:
	if t != [-1, -1]:
		q.append(t)
for t in q:
	cl = d[t[0], t[1]]
	if t[0] == 1:
		i = t[1] - 1
		for j in range(m):
			dp[i][j] = cl
	else:
		j = t[1] - 1
		for i in range(n):
			dp[i][j] = cl
for t in dp:
	print(*t)


(n, m, k) = [int(x) for x in input().split()]
r = [(0, -1) for i in range(n)]
c = [(0, -1) for i in range(m)]
for i in range(k):
	(ax, crd, clr) = [int(x) for x in input().split()]
	if ax == 1:
		r[crd - 1] = (clr, i)
	else:
		c[crd - 1] = (clr, i)
for i in range(n):
	s = []
	for j in range(m):
		clr = r[i][0] if r[i][1] > c[j][1] else c[j][0]
		s.append(str(clr))
	print(' '.join(s))


(n, m, k) = map(int, input().split())
l = [0]
r = [0] * n
c = [0] * m
ans = [['0'] * m for _ in range(n)]
for i in range(1, k + 1):
	(num, x, a) = map(int, input().split())
	l += [a]
	if num == 1:
		r[x - 1] = i
	else:
		c[x - 1] = i
for i in range(n):
	for j in range(m):
		if r[i] > c[j]:
			ans[i][j] = str(l[r[i]])
		else:
			ans[i][j] = str(l[c[j]])
print('\n'.join(map(' '.join, ans)))


(n, m, k) = map(int, input().split(' '))
(row, col) = ([(0, 0)] * n, [(0, 0)] * m)
for i in range(k):
	(t, r, a) = map(int, input().split(' '))
	if t == 1:
		row[r - 1] = (a, i + 1)
	elif t == 2:
		col[r - 1] = (a, i + 1)
sheet = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if row[i][1] >= col[j][1]:
			sheet[i][j] = row[i][0]
		else:
			sheet[i][j] = col[j][0]
	print(' '.join(map(str, sheet[i])))


from collections import defaultdict

def operationdict():
	return defaultdict(lambda : (-1, 0))
(n, m, k) = map(int, input().split())
(rows, columns) = (operationdict(), operationdict())
for i in range(k):
	(op, index, color) = map(int, input().split())
	ops = rows if op == 1 else columns
	ops[index - 1] = (i, color)
for y in range(n):
	print(' '.join((str(max(rows[y], columns[x])[1]) for x in range(m))))


(n, m, k) = map(int, input().split())
c = [(0, 0)] * (m + 1)
r = [(0, 0)] * (n + 1)
for i in range(k):
	(q, a, b) = map(int, input().split())
	if q == 1:
		r[a] = (i + 1, b)
	else:
		c[a] = (i + 1, b)
for i in range(n):
	s = []
	for j in range(m):
		t = r[i + 1][1]
		if c[j + 1][0] > r[i + 1][0]:
			t = c[j + 1][1]
		s += [str(t)]
	print(' '.join(s))


(n, m, k) = map(int, input().split())
canvas = [['0'] * m for i in range(n)]
comands = [input().split() for i in range(k)]
colored_rows = set()
colored_columns = set()
important_comands = []
while comands and len(colored_rows) != n and (len(colored_columns) != m):
	comand = comands.pop()
	if comand[0] == '1':
		if comand[1] not in colored_rows:
			important_comands.append(comand)
			colored_rows.add(comand[1])
	elif comand[1] not in colored_columns:
		important_comands.append(comand)
		colored_columns.add(comand[1])
for comand in important_comands[-1::-1]:
	(mark, number, color) = comand
	if mark == '1':
		canvas[int(number) - 1] = [color] * m
	else:
		for i in range(n):
			canvas[i][int(number) - 1] = color
for i in range(n):
	print(' '.join(canvas[i]))


import sys
import math
from collections import defaultdict
MAXNUM = math.inf
MINNUM = -1 * math.inf

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getString():
	return sys.stdin.readline().rstrip()

def solve(queries, n, m):
	paper = [[0 for _ in range(m)] for _ in range(n)]
	for row in range(n):
		for col in range(m):
			if (1, row + 1) in queries:
				rq = queries[1, row + 1]
			else:
				rq = (-1, 0)
			if (2, col + 1) in queries:
				cq = queries[2, col + 1]
			else:
				cq = (-1, 0)
			if rq > cq:
				paper[row][col] = rq[1]
			else:
				paper[row][col] = cq[1]
	return paper

def printOutput(ans):
	for lin in ans:
		for i in lin:
			sys.stdout.write(str(i) + ' ')
		sys.stdout.write('\n')

def readinput():
	(n, m, k) = getInts()
	counter = 0
	queries = {}
	for _ in range(k):
		(qType, rc, color) = getInts()
		queries[qType, rc] = (counter, color)
		counter += 1
	printOutput(solve(queries, n, m))
readinput()


(n, m, k) = map(int, input().split())
l = [[0, 0] for i in range(n + 1)]
c = [[0, 0] for i in range(m + 1)]
for i in range(k):
	(dim, ind, col) = map(int, input().split())
	ind -= 1
	if dim == 1:
		l[ind][0] = col
		l[ind][1] = i
	else:
		c[ind][0] = col
		c[ind][1] = i
for i in range(n):
	for j in range(m):
		if l[i][1] > c[j][1]:
			print(l[i][0], end=' ')
		elif l[i][1] < c[j][1]:
			print(c[j][0], end=' ')
		elif l[i][0] != 0:
			print(l[i][0], end=' ')
		else:
			print(c[j][0], end=' ')
	print()


(n, m, k) = map(int, input().split())
(row, col, color) = ([0] * n, [0] * m, [0] * k + [0])
for i in range(1, k + 1):
	(typ, pos, color[i]) = map(int, input().split())
	if typ == 1:
		row[pos - 1] = i
	else:
		col[pos - 1] = i
for i in range(n):
	out = ''
	for j in range(m):
		out += str(color[max(row[i], col[j])])
		out += ' '
	print(out)


from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

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

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

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

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

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

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(index) + 1] = int(value)
	return dic
(n, m, k) = di()
coldic = {}
rowdic = {}
for i in range(k):
	(sel, rorcol, color) = di()
	if sel == 1:
		rowdic[rorcol] = [i, color]
	else:
		coldic[rorcol] = [i, color]
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if i + 1 in rowdic and j + 1 in coldic:
			if rowdic[i + 1][0] > coldic[j + 1][0]:
				ans[i][j] = rowdic[i + 1][1]
			else:
				ans[i][j] = coldic[j + 1][1]
		elif i + 1 in rowdic:
			ans[i][j] = rowdic[i + 1][1]
		elif j + 1 in coldic:
			ans[i][j] = coldic[j + 1][1]
		print(ans[i][j], end=' ')
	print(end='\n')


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	(n, m, k) = map(int, input().split())
	B1 = [[0, 0, 0, 0] for i in range(n)]
	B2 = [[0, 0, 0, 0] for i in range(m)]
	for i in range(k):
		(a, b, c) = map(int, input().split())
		b -= 1
		if a == 1:
			B1[b] = [i, a, b, c]
		else:
			B2[b] = [i, a, b, c]
	C = sorted(B1 + B2, key=lambda x: x[0])
	A = [[0] * m for i in range(n)]
	for i in range(len(C)):
		(x, a, b, c) = C[i]
		if a == 1:
			A[b] = [c] * m
		elif a == 2:
			for j in range(n):
				A[j][b] = c
	for row in A:
		print(' '.join(map(str, row)))
main()


(n, m, k) = [int(x) for x in input().split()]
row = [(0, -1)] * n
col = [(0, -1)] * m
for i in range(0, k):
	(t, num, color) = [int(x) for x in input().split()]
	num -= 1
	if t == 1:
		row[num] = (color, i)
	else:
		assert t == 2
		col[num] = (color, i)
for r in row:
	for c in col:
		if c[1] > r[1]:
			print(c[0], end=' ')
		else:
			print(r[0], end=' ')
	print()


import sys
(n, m, k) = [int(x) for x in input().split()]
(lines, columns) = ([(0, 0, i, 1) for i in range(n)], [(0, 0, i, 2) for i in range(m)])
for (i, line) in enumerate(sys.stdin):
	(t, r, c) = [int(x) for x in line.split()]
	if t == 1:
		lines[r - 1] = (i, c, r - 1, 1)
	else:
		columns[r - 1] = (i, c, r - 1, 2)
strings = lines + columns
strings.sort()
matrix = [[0] * m for i in range(n)]
for (i, c, r, t) in strings:
	if t == 1:
		matrix[r] = [c for i in range(m)]
	else:
		for j in range(n):
			matrix[j][r] = c
for i in range(n):
	sys.stdout.write(' '.join(map(str, matrix[i])) + '\n')


def main():
	(n, m, k) = map(int, input().split())
	B1 = [[0, 0, 0, 0] for i in range(n)]
	B2 = [[0, 0, 0, 0] for i in range(m)]
	for i in range(k):
		(a, b, c) = map(int, input().split())
		b -= 1
		if a == 1:
			B1[b] = [i, a, b, c]
		else:
			B2[b] = [i, a, b, c]
	C = sorted(B1 + B2, key=lambda x: x[0])
	A = [[0] * m for i in range(n)]
	for i in range(len(C)):
		(x, a, b, c) = C[i]
		if a == 1:
			A[b] = [c] * m
		elif a == 2:
			for j in range(n):
				A[j][b] = c
	for row in A:
		print(' '.join(map(str, row)))
main()


(n, m, k) = map(int, input().split())
r = [[0, 0] for i in range(n)]
c = [[0, 0] for i in range(m)]
for _ in range(k):
	(x, w, v) = map(int, input().split())
	if x == 1:
		r[w - 1][0] = _ + 1
		r[w - 1][1] = v
	else:
		c[w - 1][0] = _ + 1
		c[w - 1][1] = v
for i in range(n):
	for j in range(m):
		if r[i][0] >= c[j][0]:
			print(r[i][1], end=' ')
		else:
			print(c[j][1], end=' ')
	print('')


s = input()
num = [int(x) for x in s.split()]
(n, m, k) = (num[0], num[1], num[2])
mat = [[0 for x in range(m)] for x in range(n)]
cT = [0 for x in range(m)]
rT = [0 for x in range(n)]
cV = [0 for x in range(m)]
rV = [0 for x in range(n)]
for i in range(1, k + 1):
	s = input()
	num = [int(x) for x in s.split()]
	(ty, j, v) = (num[0], num[1], num[2])
	j = j - 1
	if ty is 1:
		rT[j] = i
		rV[j] = v
	else:
		cT[j] = i
		cV[j] = v
for i in range(n):
	for j in range(m):
		if rT[i] > cT[j]:
			mat[i][j] = rV[i]
		else:
			mat[i][j] = cV[j]
for i in range(n):
	for j in range(m):
		if j + 1 < m:
			print(mat[i][j], end=' ')
		else:
			print(mat[i][j])


import sys
from functools import reduce

def paint_row(mat, i, color):
	row = mat[i]
	for j in range(len(row)):
		if row[j] == 0:
			row[j] = color

def paint_col(mat, j, color):
	for i in range(len(mat)):
		if mat[i][j] == 0:
			mat[i][j] = color

def main(mat, ops):
	ops.reverse()
	row_painted = set()
	col_painted = set()
	for (op, n, color) in ops:
		if op == 1 and n - 1 not in row_painted:
			paint_row(mat, n - 1, color)
			row_painted.add(n - 1)
		elif op == 2 and n - 1 not in col_painted:
			paint_col(mat, n - 1, color)
			col_painted.add(n - 1)
	for row in mat:
		print(' '.join((str(d) for d in row)))
ops = []
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		(n, m, _) = map(int, line.strip().split())
		mat = [[0 for _ in range(m)] for _ in range(n)]
		continue
	ops.append(list(map(int, line.strip().split())))
main(mat, ops)


mx = []
ops = []
nx = list(map(int, input().split()))
n = nx[0]
m = nx[1]
k = nx[2]
flagn = [(-1, -1, i) for i in range(0, n)]
flagm = [(-1, -1, i) for i in range(0, m)]
for i in range(0, n):
	mx.append([0] * m)
for i in range(0, k):
	temp = list(map(int, input().split()))
	if temp[0] == 1:
		flagn[temp[1] - 1] = (i, temp[2], temp[1] - 1)
	else:
		flagm[temp[1] - 1] = (i, temp[2], temp[1] - 1)
flagn.sort(key=lambda x: x[0])
flagm.sort(key=lambda x: x[0])
pntn = 0
pntm = 0
for i in range(0, n + m):
	if (pntn < n) & (pntm < m):
		if flagn[pntn][0] <= flagm[pntm][0]:
			if flagn[pntn][0] != -1:
				for j in range(0, m):
					mx[flagn[pntn][2]][j] = flagn[pntn][1]
			i += 1
			pntn += 1
		else:
			if flagm[pntm][0] != -1:
				for j in range(0, n):
					mx[j][flagm[pntm][2]] = flagm[pntm][1]
			i += 1
			pntm += 1
	else:
		if pntn < n:
			if flagn[pntn][0] != -1:
				for j in range(0, m):
					mx[flagn[pntn][2]][j] = flagn[pntn][1]
			i += 1
			pntn += 1
		if pntm < m:
			if flagm[pntm][0] != -1:
				for j in range(0, n):
					mx[j][flagm[pntm][2]] = flagm[pntm][1]
			i += 1
			pntm += 1
for i in range(0, n):
	for j in range(0, m):
		print(mx[i][j], end=' ')
	print()


(n, m, k) = map(int, input().split())
r = [0] * n
c = [0] * m
color = [0] * (max(max(n, m), k) + 1)
for q in range(1, k + 1):
	(check, no, color[q]) = map(int, input().split())
	if check == 1:
		r[no - 1] = q
	else:
		c[no - 1] = q
for i in range(n):
	st = str()
	for j in range(m):
		st += str(color[max(r[i], c[j])])
		st += ' '
	print(st)


(n, m, k) = map(int, input().split())
a = [(0, -1)] * n
b = [(0, -1)] * m
for i in range(k):
	(t, pl, col) = map(int, input().split())
	if t == 1:
		a[pl - 1] = (col, i)
	else:
		b[pl - 1] = (col, i)
for i in range(n):
	for j in range(m):
		if a[i][1] > b[j][1]:
			print(a[i][0], end=' ')
		else:
			print(b[j][0], end=' ')
	print()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def seive():
	prime = [1 for i in range(10 ** 6 + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(10 ** 6 + 1):
		if prime[i]:
			for j in range(2 * i, 10 ** 6 + 1, i):
				prime[j] = 0
	return prime
(n, m, k) = L()
A = [L() for i in range(k)]
r = [[0, 0] for i in range(n)]
c = [[0, 0] for j in range(m)]
for i in range(1, k + 1):
	(code, x, a) = A[i - 1]
	if code == 1:
		r[x - 1] = [a, i]
	else:
		c[x - 1] = [a, i]
dp = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		(r1, rt) = r[i]
		(c1, ct) = c[j]
		if rt > ct:
			dp[i][j] = r1
		else:
			dp[i][j] = c1
pmat(dp)
endtime = time.time()


import sys

def input():
	return sys.stdin.readline().strip()
(n, m, k) = map(int, input().split())
table = [[0 for i in range(m)] for j in range(n)]

def row_col(x, a):
	for i in range(m):
		if not table[x][i]:
			table[x][i] = a

def col_col(x, a):
	for i in range(n):
		if not table[i][x]:
			table[i][x] = a
color = [[0, 0, 0] for i in range(n + m)]
for i in range(k):
	(t, r, a) = map(int, input().split())
	color[(t - 1) * n + (r - 1)] = [i, (t - 1) * n + (r - 1), a]
color.sort(reverse=True)
for i in range(n + m):
	if not color[i][2]:
		break
	if color[i][1] >= n:
		x = color[i][1] - n
		for j in range(n):
			if not table[j][x]:
				table[j][x] = color[i][2]
	else:
		x = color[i][1]
		for j in range(m):
			if not table[x][j]:
				table[x][j] = color[i][2]
for i in range(n):
	for j in range(m):
		print(table[i][j], end=' ')
	print()


(n, m, k) = map(int, input().split())
ultimoLinha = [0] * n
ultimoColuna = [0] * m
cor = [0] * (k + 1)
for op in range(1, k + 1):
	(o, r, cor[op]) = map(int, input().split())
	if o == 1:
		ultimoLinha[r - 1] = op
	else:
		ultimoColuna[r - 1] = op
for i in range(n):
	printar = ''
	for j in range(m):
		printar += str(cor[max(ultimoColuna[j], ultimoLinha[i])])
		printar += ' '
	print(printar)


(n, m, k) = map(int, input().split())
c = [0] * m
r = [0] * n
x = []
for i in range(n):
	x.append([0] * m)
for i in range(k):
	(a, b, d) = map(int, input().split())
	if a == 1:
		r[b - 1] = [d, i]
	else:
		c[b - 1] = [d, i]
for i in range(n):
	for j in range(m):
		if r[i] == 0 and c[j] == 0:
			continue
		elif r[i] == 0:
			x[i][j] = c[j][0]
		elif c[j] == 0:
			x[i][j] = r[i][0]
		elif r[i][1] > c[j][1]:
			x[i][j] = r[i][0]
		else:
			x[i][j] = c[j][0]
for i in range(n):
	for j in range(m):
		print(x[i][j], end=' ')
	print('')


__author__ = 'aste'

def main():
	(n, m, k) = map(int, input().split())
	rows = [(0, 0)] * n
	cols = [(0, 0)] * m
	for i in range(1, k + 1):
		(op, rc, a) = map(int, input().split())
		if op == 1:
			rows[rc - 1] = (a, i)
		else:
			cols[rc - 1] = (a, i)
	for i in range(0, n):
		for j in range(0, m):
			row = rows[i]
			col = cols[j]
			if row[1] < col[1]:
				print(col[0], end=' ')
			else:
				print(row[0], end=' ')
		print()
main()


(n, m, k) = list(map(int, input().split()))
rows = [(-1, 0)] * n
cols = [(-1, 0)] * m
for q in range(k):
	(t, i, color) = list(map(int, input().split()))
	i -= 1
	if t == 1:
		rows[i] = (q, color)
	else:
		cols[i] = (q, color)
for r in range(n):
	row = rows[r]
	for c in range(m):
		col = cols[c]
		color = max(row, col)[1]
		print(color, end=' ')
	print()


(n, m, k) = map(int, input().split())
lines = [[0, 0] for i in range(n)]
columns = [[0, 0] for i in range(m)]
for i in range(k):
	(task, num, color) = map(int, input().split())
	if task == 1:
		lines[num - 1] = [color, i + 1]
	else:
		columns[num - 1] = [color, i + 1]
for i in range(n):
	for j in range(m):
		if lines[i][1] > columns[j][1]:
			print(lines[i][0], end=' ')
		else:
			print(columns[j][0], end=' ')
	print('')


(n, m, k) = map(int, input().split())
c = [(0, 0)] * m
r = [(0, 0)] * n
for i in range(k):
	(t, idx, x) = map(int, input().split())
	if t == 1:
		r[idx - 1] = (i + 1, x)
	else:
		c[idx - 1] = (i + 1, x)
res = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		res[i][j] = c[j][1] if c[j][0] > r[i][0] else r[i][1]
[print(*i) for i in res]


(n, m, k) = map(int, input().split())
colors = [0] * (k + 1)
columns_t = [0] * m
rows_t = [0] * n
for i in range(1, k + 1):
	(mode, num, colors[i]) = map(int, input().split())
	if mode == 1:
		rows_t[num - 1] = i
	else:
		columns_t[num - 1] = i
for i in range(n):
	ans = str()
	for j in range(m):
		ans += str(colors[max(rows_t[i], columns_t[j])])
		ans += ' '
	print(ans)


def get_ints():
	return [int(x) for x in input().split()]
(n, m, k) = get_ints()
ar = [[0] * m for i in range(n)]
lastr = [0] * n
lastc = [0] * m
colors = [0] * (k + 1)
for i in range(1, k + 1):
	(t, a, b) = get_ints()
	colors[i] = b
	if t == 1:
		lastr[a - 1] = i
	else:
		lastc[a - 1] = i
for i in range(n):
	row = ''
	for j in range(m):
		row += str(colors[max(lastr[i], lastc[j])])
		row += ' '
	print(row)


(n, m, k) = map(int, input().split())
stol = [[0, -1] for i in range(m)]
strok = [[0, -1] for i in range(n)]
for i in range(k):
	(c, ri, ai) = map(int, input().split())
	if c == 1:
		strok[ri - 1][0] = ai
		strok[ri - 1][1] = i
	else:
		stol[ri - 1][0] = ai
		stol[ri - 1][1] = i
data = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if strok[i][1] > stol[j][1]:
			data[i][j] = strok[i][0]
		else:
			data[i][j] = stol[j][0]
for i in range(n):
	print(*data[i])


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, k) = map(int, input().split())
columns = [0] * m
rows = [0] * n
colors = [0 for i in range(k + 1)]
for q in range(1, k + 1):
	(type, r, color) = map(int, input().split())
	if type == 1:
		rows[r - 1] = q
	if type == 2:
		columns[r - 1] = q
	colors[q] = color
res = []
for i in range(n):
	row = []
	for j in range(m):
		row.append(str(colors[max(columns[j], rows[i])]))
	res.append(' '.join(row))
print('\n'.join(res))


import sys
from math import *
from random import *

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, m, k) = mints()
r = [(0, -1)] * n
c = [(0, -1)] * m
for i in range(k):
	(t, x, a) = mints()
	if t == 1:
		r[x - 1] = (a, i)
	else:
		c[x - 1] = (a, i)
for i in range(n):
	for j in range(m):
		if r[i][1] > c[j][1]:
			print(r[i][0], end=' ')
		else:
			print(c[j][0], end=' ')
	print()


(n, m, k) = (int(i) for i in input().split(' '))
sheet = [[0 for j in range(m)] for i in range(n)]
num_rows = n
num_cols = m
num_ops = k

def print_sheet(sheet):
	for row in sheet:
		print(' '.join((str(cell) for cell in row)))

def paint_row(ri, color):
	row = sheet[ri]
	for i in range(num_cols):
		row[i] = color

def paint_col(ci, color):
	for i in range(num_rows):
		sheet[i][ci] = color
row_paints = {}
col_paints = {}

def prepaint_row(ri, color, op_num):
	row_paints[ri] = (color, op_num)

def prepaint_col(ci, color, op_num):
	col_paints[ci] = (color, op_num)
for i in range(k):
	(op, index, color) = (int(i) for i in input().split(' '))
	if op == 1:
		prepaint_row(index - 1, color, i)
	else:
		prepaint_col(index - 1, color, i)
all_ops = []
ROW = 1
COL = 2
for (ri, value) in row_paints.items():
	all_ops.append([ROW, ri, value[0], value[1]])
for (ci, value) in col_paints.items():
	all_ops.append([COL, ci, value[0], value[1]])
from operator import itemgetter
all_ops.sort(key=itemgetter(3))
for (op, index, color, i) in all_ops:
	if op == ROW:
		paint_row(index, color)
	else:
		paint_col(index, color)
print_sheet(sheet)


def STR():
	return list(input())

def INT():
	return int(input())

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

def MAP2():
	return map(float, input().split())

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

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, m, k) = MAP()
rows = [[0, -1] for i in range(n)]
cols = [[0, -1] for i in range(m)]
for i in range(k):
	(x, y, z) = MAP()
	if x == 1:
		rows[y - 1][0] = z
		rows[y - 1][1] = i
	else:
		cols[y - 1][0] = z
		cols[y - 1][1] = i
g = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if rows[i][1] > cols[j][1]:
			g[i][j] = rows[i][0]
		else:
			g[i][j] = cols[j][0]
for i in range(n):
	for j in range(m):
		print(g[i][j], end=' ')
	print()


from sys import stdin, stdout
(a, b, c) = map(int, stdin.readline().split())
row = [0] * a
col = [0] * b
matrix = []
for i in ' ' * a:
	matrix += [[0] * b]
z = []
for _ in ' ' * c:
	z += [list(map(int, stdin.readline().split()))]
z = z[::-1]
for i in z[:min(a * b, c)]:
	i[1] -= 1
	if i[0] == 1:
		if row[i[1]] == 0:
			row[i[1]] = 1
			for j in range(b):
				if col[j] == 0:
					matrix[i[1]][j] = i[2]
	elif col[i[1]] == 0:
		col[i[1]] = 1
		for j in range(a):
			if row[j] == 0:
				matrix[j][i[1]] = i[2]
s = ''
for i in range(a):
	s += ' '.join(map(str, matrix[i])) + '\n'
stdout.write(s)


import sys
input = sys.stdin.readline
(n, m, k) = [int(x) for x in input().split(' ')]
d = {}
for row in range(1, n + 1):
	d[1, row] = (-1, 0)
for col in range(1, m + 1):
	d[2, col] = (-1, 0)
for op in range(k):
	s = [int(x) for x in input().split(' ')]
	d[s[0], s[1]] = (op, s[2])
for row in range(1, n + 1):
	r = []
	for col in range(1, m + 1):
		r.append(max(d[1, row], d[2, col])[1])
	print(*r)


inp = lambda : map(int, input().split())
(n, m, k) = inp()
data = [(0, 0, i) for i in range(n + m)]
for i in range(k):
	(query, id, color) = inp()
	if query == 1:
		data[id - 1] = (i, color, id - 1)
	else:
		data[id - 1 + n] = (i, color, id - 1 + n)
data.sort()
field = [[0] * m for _ in range(n)]
for (_, color, id) in data:
	if color != 0:
		if id < n:
			for i in range(m):
				field[id][i] = color
		else:
			for i in range(n):
				field[i][id - n] = color
for i in range(n):
	print(*field[i])


(n, m, k) = map(int, input().split())
t = [[0] * m for i in range(n)]
used = set()
a = []
for i in range(k):
	(q, b, c) = tuple(map(int, input().split()))
	b = b - 1
	a.append((q, b, c))
a = a[::-1]
for i in range(k):
	if a[i][0:2] not in used:
		if a[i][0] == 1:
			for s in range(m):
				if t[a[i][1]][s] == 0:
					t[a[i][1]][s] = a[i][2]
		else:
			for s in range(n):
				if t[s][a[i][1]] == 0:
					t[s][a[i][1]] = a[i][2]
		used.add(a[i][0:2])
for i in range(n):
	for j in range(m):
		print(t[i][j], end=' ')
	print()


(n, m, k) = map(int, input().split())
r = [0] * n
c = [0] * m
t = [0] * (k + 1)
for i in range(1, k + 1):
	(a, b, t[i]) = map(int, input().split())
	if a == 1:
		r[b - 1] = i
	else:
		c[b - 1] = i
for i in range(n):
	ans = str()
	for j in range(m):
		ans += str(t[max(r[i], c[j])])
		ans += ' '
	print(ans)


(n, m, k) = [int(x) for x in input().split()]
a = []
r = [(0, 0)] * n
c = [(0, 0)] * m
for i in range(n):
	a.append([0] * m)
for _ in range(k):
	(x, y, z) = [int(t) for t in input().split()]
	if x == 1:
		r[y - 1] = (_, z)
	else:
		c[y - 1] = (_, z)
for i in range(n):
	for j in range(m):
		a[i][j] = max(r[i], c[j])[1]
	print(*a[i])


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq 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')

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, k) = value()
C_prior = defaultdict(lambda : 0)
R_prior = defaultdict(lambda : 0)
color_R = defaultdict(lambda : 0)
color_C = defaultdict(lambda : 0)
for i in range(k):
	(t, num, col) = value()
	if t == 1:
		R_prior[num - 1] = i + 1
		color_R[num - 1] = col
	else:
		C_prior[num - 1] = i + 1
		color_C[num - 1] = col
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if R_prior[i] > C_prior[j]:
			ans[i][j] = color_R[i]
		else:
			ans[i][j] = color_C[j]
		print(ans[i][j], end=' ')
	print()


s = input()
s = s.split(' ')
n = int(s[0])
m = int(s[1])
k = int(s[2])
Rows = [0 for i in range(n)]
Colomnes = [0 for i in range(m)]
Colors = [0 for i in range(k + 1)]
for i in range(k):
	s = input()
	s = s.split(' ')
	rorc = int(s[0])
	num = int(s[1])
	Colors[i + 1] = int(s[2])
	if rorc == 1:
		Rows[num - 1] = i + 1
	else:
		Colomnes[num - 1] = i + 1
for i in range(n):
	for j in range(m):
		print(Colors[max(Rows[i], Colomnes[j])], end=' ')
	print()


(n, m, k) = map(int, input().split())
row = [0] * n
col = [0] * m
for i in range(k):
	(t, rc, a) = map(int, input().split())
	rc -= 1
	if t == 1:
		row[rc] = (i, a)
	else:
		col[rc] = (i, a)
for i in range(n):
	for j in range(m):
		if type(row[i]) == tuple and type(col[j]) != tuple:
			upd = row[i]
		elif type(row[i]) != tuple and type(col[j]) == tuple:
			upd = col[j]
		else:
			upd = max(row[i], col[j])
		if upd is 0:
			print(0, end=' ')
		else:
			print(upd[1], end=' ')
	print()


(n, m, k) = map(int, input().split())
row_color = [0] * n
row_time = [0] * n
col_color = [0] * m
col_time = [0] * m
for i in range(k):
	(cmd, idx, color) = map(int, input().split())
	idx -= 1
	if cmd == 1:
		row_color[idx] = color
		row_time[idx] = i + 1
	else:
		col_color[idx] = color
		col_time[idx] = i + 1
a = [[0] * m for _ in range(n)]
for i in range(n):
	for j in range(m):
		if row_time[i] > col_time[j]:
			a[i][j] = row_color[i]
		else:
			a[i][j] = col_color[j]
print('\n'.join(map(lambda row: ' '.join(map(str, row)), a)))


from collections import defaultdict, deque, Counter, OrderedDict
import threading, sys

def main():
	(n, m, k) = map(int, input().split())
	nl = [(-1, 0) for i in range(n)]
	ml = [(-1, 0) for i in range(m)]
	for i in range(k):
		(a, b, c) = map(int, input().split())
		if a == 1:
			nl[b - 1] = (i, c)
		else:
			ml[b - 1] = (i, c)
	for i in range(n):
		for j in range(m):
			print(nl[i][1] if nl[i][0] > ml[j][0] else ml[j][1], end=' ')
		print()
main()


(n, m, k) = map(int, input().split())
mat = [{}, {}]
for i in range(k):
	(t, x, c) = map(int, input().split())
	mat[t - 1][x - 1] = (i, c)
res = []
for i in [0, 1]:
	for (k, v) in mat[i].items():
		res.append((v[0], i, k, v[1]))
res.sort()
ans = [[0] * m for _ in range(n)]
for (_, t, x, c) in res:
	if t == 0:
		for i in range(m):
			ans[x][i] = c
	else:
		for i in range(n):
			ans[i][x] = c
for l in ans:
	print(*l)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, m, k) = invr()
row = [-1] * (n + 1)
cr = [0] * (n + 1)
col = [-1] * (m + 1)
cc = [0] * (m + 1)
for i in range(k):
	(a, b, c) = invr()
	if a == 1:
		row[b] = i + 1
		cr[b] = c
	else:
		col[b] = i + 1
		cc[b] = c
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if row[i] > col[j]:
			print(cr[i], end=' ')
		else:
			print(cc[j], end=' ')
	print()


(n, m, k) = [int(x) for x in input().split()]
instante_linhas = [0] * n
instante_colunas = [0] * m
cores = [0] * (k + 1)
for i in range(k):
	(op, lc, cor) = [int(x) for x in input().split()]
	cores[i + 1] = cor
	if op == 1:
		instante_linhas[lc - 1] = i + 1
	elif op == 2:
		instante_colunas[lc - 1] = i + 1
resp = ''
for i in range(n):
	for j in range(m):
		resp += str(cores[max(instante_linhas[i], instante_colunas[j])])
		if j != m - 1:
			resp += ' '
	if i != n - 1:
		resp += '\n'
print(resp)


import math
from sys import stdin, stdout
(n, m, k) = list(map(int, stdin.readline().split()))
row_p = [0] * n
col_p = [0] * m
row_c = [0] * n
col_c = [0] * m
for i in range(1, k + 1):
	(t, num, color) = list(map(int, stdin.readline().split()))
	num -= 1
	if t == 1:
		row_c[num] = color
		row_p[num] = i
	else:
		col_c[num] = color
		col_p[num] = i
matrix = [[0 for x in range(m)] for y in range(n)]
for i in range(n):
	for j in range(m):
		if row_p[i] > col_p[j]:
			matrix[i][j] = row_c[i]
		else:
			matrix[i][j] = col_c[j]
for i in range(n):
	print(*matrix[i])


from sys import stdin

def main():
	nextint = iter(map(int, stdin.read().split())).__next__
	(n, m, k) = (nextint(), nextint(), nextint())
	rowup = [(0, -1) for _ in range(n)]
	colup = [(0, -1) for _ in range(m)]
	for x in range(k):
		if nextint() == 1:
			(r, v) = (nextint() - 1, nextint())
			rowup[r] = (v, x)
		else:
			(c, v) = (nextint() - 1, nextint())
			colup[c] = (v, x)
	mout = []
	for x in range(n):
		out = []
		for y in range(m):
			out.append(rowup[x][0] if rowup[x][1] > colup[y][1] else colup[y][0])
		mout.append(' '.join(map(str, out)))
	print('\n'.join(mout))
main()


def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return [str(x) for x in stdin.readline().split()]
from sys import stdin
from collections import *
(n, m, k) = arr_inp(1)
(row, col) = (defaultdict(list), defaultdict(list))
for i in range(k):
	(num, x, y) = arr_inp(1)
	if num == 1:
		row[x - 1] = [y, i]
	else:
		col[x - 1] = [y, i]
for i in range(n):
	for j in range(m):
		if row[i]:
			if col[j]:
				print(row[i][0] if col[j][1] < row[i][1] else col[j][0], end=' ')
			else:
				print(row[i][0], end=' ')
		elif col[j]:
			if row[i]:
				print(row[i][0] if col[j][1] < row[i][1] else col[j][0], end=' ')
			else:
				print(col[j][0], end=' ')
		else:
			print(0, end=' ')
	print(end='\n')


(n, m, k) = map(int, input().split())
columns = [[0] * 2 for i in range(n)]
strokes = [[0] * 2 for i in range(m)]
for i in range(n):
	columns[i][1] = -1
for i in range(m):
	strokes[i][1] = -1
for i in range(k):
	(num, rci, ai) = map(int, input().split())
	if num == 2:
		strokes[rci - 1][0] = ai
		strokes[rci - 1][1] = i
	else:
		columns[rci - 1][0] = ai
		columns[rci - 1][1] = i
nm = [[[0] * 2 for i in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if columns[i][1] >= nm[i][j][1]:
			nm[i][j][0] = columns[i][0]
			nm[i][j][1] = columns[i][1]
		if strokes[j][1] >= nm[i][j][1]:
			nm[i][j][0] = strokes[j][0]
			nm[i][j][1] = strokes[j][1]
for i in range(n):
	for j in range(m):
		print(nm[i][j][0], end=' ')
	print()


(n, m, k) = map(int, input().split())
A = [0] * n
for i in range(n):
	A[i] = [0, 0]
B = [0] * m
for i in range(m):
	B[i] = [0, 0]
for i in range(k):
	per = input().split()
	if per[0] == '1':
		A[int(per[1]) - 1] = [int(per[2]), i + 1]
	else:
		B[int(per[1]) - 1] = [int(per[2]), i + 1]
ans = [0] * n
for i in range(n):
	ans[i] = [0] * m
for i in range(n):
	for j in range(m):
		if A[i][1] > B[j][1]:
			ans[i][j] = A[i][0]
		else:
			ans[i][j] = B[j][0]
for i in ans:
	print(' '.join(map(str, i)))


import os
import sys
import math
from io import BytesIO, IOBase
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')

def main():
	(n, m, k) = map(int, input().split())
	grid = [[0 for i in range(m)] for i in range(n)]
	(row_val, col_val) = ([0 for i in range(n)], [0 for i in range(m)])
	(row_time, col_time) = ([-1 for i in range(n)], [-1 for i in range(m)])
	temp = k
	while temp:
		(op, no, val) = map(int, input().split())
		if op == 1:
			row_val[no - 1] = val
			row_time[no - 1] = k - temp
		else:
			col_val[no - 1] = val
			col_time[no - 1] = k - temp
		temp -= 1
	for i in range(n):
		for j in range(m):
			if max(col_time[j], row_time[i]) == -1:
				continue
			if row_time[i] > col_time[j]:
				grid[i][j] = row_val[i]
			else:
				grid[i][j] = col_val[j]
	for i in range(n):
		for j in range(m):
			sys.stdout.write(str(grid[i][j]) + ' ')
		sys.stdout.write('\n')
main()


(n, m, k) = map(int, input().split())
TimeA = [0] * n
TimeB = [0] * m
color = [0] * 100009
for i in range(1, k + 1):
	(choice, type, color[i]) = map(int, input().split())
	if choice == 1:
		TimeA[type - 1] = i
	else:
		TimeB[type - 1] = i
for i in range(n):
	for j in range(m):
		print(color[max(TimeA[i], TimeB[j])], end=' ')
	print()


read = lambda : map(int, input().split())
(n, m, k) = read()
c = [(0, 0)] * m
r = [(0, 0)] * n
for i in range(k):
	(t, a, x) = read()
	if t == 1:
		r[a - 1] = (i + 1, x)
	else:
		c[a - 1] = (i + 1, x)
a = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		a[i][j] = c[j][1] if c[j][0] > r[i][0] else r[i][1]
[print(*i) for i in a]


(n, m, k) = [int(i) for i in input().split()]
printops = []
for i in range(k):
	printops.append([int(i) for i in input().split()])

def pm():
	for r in matrix:
		for i in r:
			print(i, end=' ')
		print()
row_status = [True] * n
col_status = [True] * m
matrix = [[0] * m for i in range(n)]
for i in range(k):
	j = k - i - 1
	(rc_indicator, rc, color) = printops[j]
	rc -= 1
	if rc_indicator == 1:
		if row_status[rc]:
			for c in range(m):
				if col_status[c]:
					matrix[rc][c] = color
			row_status[rc] = False
	elif col_status[rc]:
		for r in range(n):
			if row_status[r]:
				matrix[r][rc] = color
		col_status[rc] = False
pm()