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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') positive = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline char RC() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b, long long MOD) {
  return a / gcd(a, b) * b % MOD;
}
inline long long Sub(long long x, long long y, long long mod) {
  long long res = x - y;
  while (res < 0) res += mod;
  return res;
}
inline long long Add(long long x, long long y, long long mod) {
  long long res = x + y;
  while (res >= mod) res -= mod;
  return res;
}
inline long long POW_MOD(long long x, long long y, long long mod) {
  long long ret = 1;
  while (y > 0) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}
const int N = 1000005 + 100;
const int M = 400000 + 100;
const long long INF = 9e18;
const int inf = 0x7fffffff;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double G = 9.8;
const double eps = 1e-3;
struct Operation {
  int op, id, color;
  Operation(int x, int y, int z) : op(x), id(y), color(z) {}
};
vector<Operation> ope, rlt;
bool col[N], row[N];
int ans[5005][5005];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < k; ++i) {
    int op, id, color;
    scanf("%d%d%d", &op, &id, &color);
    ope.push_back(Operation(op, id, color));
  }
  for (int i = k - 1; i >= 0; --i) {
    int op = ope[i].op, id = ope[i].id, color = ope[i].color;
    if (op == 1) {
      if (!row[id]) {
        rlt.push_back(Operation(op, id, color));
        row[id] = true;
      }
    } else {
      if (!col[id]) {
        rlt.push_back(Operation(op, id, color));
        col[id] = true;
      }
    }
  }
  for (Operation v : rlt) {
    int op = v.op, id = v.id, color = v.color;
    if (op == 1) {
      for (int i = 1; i <= m; ++i) {
        if (ans[id][i] == 0) ans[id][i] = color;
      }
    } else {
      for (int i = 1; i <= n; ++i) {
        if (ans[i][id] == 0) ans[i][id] = color;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cout << ans[i][j];
      if (j != m) cout << " ";
    }
    cout << endl;
  }
  return 0;
}