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: 
 1.  Paint all cells in row *r*<sub class="lower-index">*i*</sub> in color *a*<sub class="lower-index">*i*</sub>; 1.  Paint all cells in column *c*<sub class="lower-index">*i*</sub> in color *a*<sub class="lower-index">*i*</sub>. 
If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a*<sub class="lower-index">*i*</sub>.

Your program has to print the resulting table after *k* operation.
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*<sub class="lower-index">*i*</sub> *a*<sub class="lower-index">*i*</sub> (1 ≤ *r*<sub class="lower-index">*i*</sub> ≤ *n*, 1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>), means that row *r*<sub class="lower-index">*i*</sub> is painted in color *a*<sub class="lower-index">*i*</sub>; -  2 *c*<sub class="lower-index">*i*</sub> *a*<sub class="lower-index">*i*</sub> (1 ≤ *c*<sub class="lower-index">*i*</sub> ≤ *m*, 1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>), means that column *c*<sub class="lower-index">*i*</sub> is painted in color *a*<sub class="lower-index">*i*</sub>.
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.
3 3 3
1 1 3
2 2 1
1 2 2
3 1 3 
2 2 2 
0 1 0 
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
1 1 1 
1 0 1 
1 1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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
10 1 1
2 1 1000000000
1000000000 
1000000000 
1000000000 
1000000000 
1000000000 
1000000000 
1000000000 
1000000000 
1000000000 
1000000000 
1 10 1
1 1 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 
5000 20 15
2 13 447246914
2 10 89345638
2 6 393683717
2 1 62225152
2 12 990340161
2 4 227462932
1 4011 327145900
1 1915 981331082
1 802 437883065
2 11 205232924
2 15 303578182
1 2667 835309719
2 3 550440583
1 3852 766318960
2 5 204700467
62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 
62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 
62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 
62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 
62225152 0 550440583 227462932 ...
20 5000 15
1 14 94104058
1 3 170575572
1 12 613859505
2 4797 363375206
1 10 554079405
2 4481 223609505
2 4974 385117513
1 7 363246561
2 2503 128936152
1 2 152944073
1 14 25797327
1 20 258831369
1 10 453164078
2 2159 753235825
2 1823 827844660
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
1 1 1
1 1 1
1 
1 1 1
1 1 1000000000
1000000000 
1 1 2
1 1 123
1 1 321
321 
1 1 2
1 1 321
1 1 123
123 
import math
import sys
import collections
import bisect
import string
import time
def get_ints():return map(int, sys.stdin.readline().strip().split())
def get_list():return list(map(int, sys.stdin.readline().strip().split()))
def get_string():return sys.stdin.readline().strip()
for t in range(1):
    n,m,k=get_ints()
    arr=[]
    for i in range(n):
        row=[0]*m
        arr.append(row)
    for i in range(k):
        a,b,c=get_ints()
        if a==1:
            #we paint rows
            for j in range(m):
                arr[b-1][j]=c
        else:
            for j in range(n):
                arr[j][b-1]=c
    for i in arr:
        print(*i)