Problem: 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 ri in color ai; 
  2. Paint all cells in column ci in color ai. 



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

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 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai; 
  * 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai. 

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>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long r[5000], r1[5000], c[5000], c1[5000];
long long POWER(long long x, long long n) {
  if (n == 0) return 1;
  long long res = x;
  while (--n) res *= x;
  return res;
}
template <typename MY_T>
void SHOW(MY_T a[], long long min, long long max) {
  long long i;
  for (i = min; i <= max; i++) {
    cout << a[i];
    if (i < max) cout << ' ';
  }
}
template <typename MY_T>
void READ(MY_T a[], long long min, long long max) {
  long long i;
  for (i = min; i <= max; i++) cin >> a[i];
}
template <typename MY_T>
bool IS_A(MY_T a[], long long min, long long max) {
  long long i;
  for (i = min + 1; i <= max; i++) {
    if (a[i] < a[i - 1]) return false;
  }
  return true;
}
template <typename MY_T>
bool IS_D(MY_T a[], long long min, long long max) {
  long long i;
  for (i = min + 1; i <= max; i++) {
    if (a[i] > a[i - 1]) return false;
  }
  return true;
}
template <typename MY_T>
void MERGE(char c, MY_T a[], long long min, long long mid, long long max) {
  long long temp[5000], j = min, k, m = mid + 1, i = min;
  if (c == 'a') {
    for (; j <= mid && m <= max; i++)
      temp[i] = (a[j] >= a[m]) ? a[m++] : a[j++];
  } else {
    for (; j <= mid && m <= max; i++)
      temp[i] = (a[j] <= a[m]) ? a[m++] : a[j++];
  }
  if (j > mid)
    for (k = m; k <= max; k++) temp[i++] = a[k];
  else
    for (k = j; k <= mid; k++) temp[i++] = a[k];
  for (i = min; i <= max; i++) a[i] = temp[i];
}
template <typename MY_T>
void SPLIT(char c, MY_T a[], long long min, long long max) {
  if (max > min) {
    long long mid = (max + min) / 2;
    SPLIT(c, a, min, mid);
    SPLIT(c, a, mid + 1, max);
    MERGE(c, a, min, mid, max);
  }
}
bool EVEN(long long x) { return !(x % 2); }
bool ODD(long long x) { return (x % 2); }
template <typename MY_T>
void SWAP(MY_T* x, MY_T* y) {
  long long h;
  h = *x;
  *x = *y;
  *y = h;
}
long long MAX(long long x, long long y) { return (x > y) ? x : y; }
long long MIN(long long x, long long y) { return (x < y) ? x : y; }
long long MAX(long long x, long long y, long long z) {
  return (x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z);
}
long long MIN(long long x, long long y, long long z) {
  return (x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z);
}
long long FACTORIAL(long long x) {
  if (x == 0 || x == 1) return 1;
  long long i;
  for (i = x - 1; i > 1; i--) x *= i;
  return x;
}
long long SUM_1_N_1(long long x) { return x * (x - 1) / 2; }
long long SUM_1_N(long long x) { return x * (x + 1) / 2; }
template <typename MY_T>
long long MAX(MY_T a[], long long min, long long max) {
  if (max == min) return *a;
  long long m = a[min], i = min;
  for (; i <= max; i++)
    if ((*(a + i)) > m) m = *(a + i);
  return m;
}
template <typename MY_T>
long long MIN(MY_T a[], long long min, long long max) {
  if (max == min) return *a;
  long long m = a[min], i = min;
  for (; i <= max; i++)
    if ((*(a + i)) < m) m = *(a + i);
  return m;
}
template <typename MY_T>
void READ_2(MY_T a[][5000], long long r, long long c) {
  long long i, j;
  for (i = 0; i <= r; i++)
    for (j = 0; j <= c; j++) cin >> a[i][j];
}
void READ_2_CHAR(char a[][5000], long long r, long long c) {
  long long i, j;
  for (i = 0; i <= r; i++)
    for (j = 0; j <= c; j++) cin >> a[i][j];
}
void SHOW_2_CHAR(char a[][5000], long long r, long long c) {
  long long i, j;
  for (i = 0; i <= r; i++)
    for (j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c)
        cout << ' ';
      else if (j == c && i < r)
        cout << endl;
    }
}
template <typename MY_T>
void SHOW_2(MY_T a[][5000], long long r, long long c) {
  long long i, j;
  for (i = 0; i <= r; i++)
    for (j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c)
        cout << ' ';
      else if (j == c && i < r)
        cout << endl;
    }
}
long long GCD(long long x, long long y) {
  if (x == y) return x;
  if (x > y) return GCD(x - y, y);
  return GCD(x, y - x);
}
long long CMD(long long x, long long y) { return x * y / GCD(x, y); }
int main() {
  long long n, m, k, i, t, l, a;
  cin >> n >> m >> k;
  for (i = 0; i < n; i++) r1[i] = -1;
  for (i = 0; i < m; i++) c1[i] = -1;
  for (i = 0; i < k; i++) {
    cin >> t >> l >> a;
    if (t == 1) {
      r[l - 1] = a;
      r1[l - 1] = i;
    } else {
      c[l - 1] = a;
      c1[l - 1] = i;
    }
  }
  for (i = 0; i < n; i++) {
    for (k = 0; k < m; k++) {
      if (r1[i] == -1) {
        cout << c[k] << ' ';
        continue;
      }
      if (c1[k] == -1) {
        cout << r[i] << ' ';
        continue;
      }
      if (r1[i] > c1[k])
        cout << r[i];
      else
        cout << c[k];
      cout << ' ';
    }
    cout << endl;
  }
}