#include <bits/stdc++.h>
using namespace std;
struct P {
  int a, b, c;
};
P ops[100010];
int g[5010][5010];
int n, m, k;
map<int, list<pair<int, int>>> htable;
void paint(int i) {
  if (ops[i].a == 1) {
    for (int c = 1; c <= m; c++) {
      if (g[ops[i].b][c] == 0) {
        g[ops[i].b][c] = ops[i].c;
      }
    }
  } else {
    for (int r = 1; r <= n; r++) {
      if (g[r][ops[i].b] == 0) {
        g[r][ops[i].b] = ops[i].c;
      }
    }
  }
}
int main() {
  cin >> n >> m >> k;
  memset(g, 0, sizeof(g));
  for (int i = 1; i <= k; i++) {
    cin >> ops[i].a >> ops[i].b >> ops[i].c;
  }
  for (int i = k; i >= 1; i--) {
    int key = (ops[i].a * ops[i].a + ops[i].b * ops[i].b) % 9949;
    if (htable.find(key) == htable.end()) {
      paint(i);
      htable[key].push_back(make_pair(ops[i].a, ops[i].b));
    } else {
      bool found = false;
      for (auto p : htable[key]) {
        if (ops[i].a == p.first && ops[i].b == p.second) {
          found = true;
          break;
        }
      }
      if (!found) {
        paint(i);
        htable[key].push_back(make_pair(ops[i].a, ops[i].b));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << g[i][j];
      if (j != m) cout << " ";
    }
    cout << endl;
  }
  return 0;
}
