#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > rlist[5000], clist[5000];
pair<int, pair<int, int> > testing;
int arr[5000][5000], i, j, n, t, tc, x, y, a, xx, yy, b, r, c, temp;
void cok() {
  for (xx = 0; xx < r; xx++) {
    for (yy = 0; yy < c; yy++) {
      printf("%d ", arr[xx][yy]);
    }
    printf("\n");
  }
}
int main() {
  scanf("%d %d %d", &r, &c, &n);
  for (i = 0; i < r; i++) {
    rlist[i].second.first = i;
    rlist[i].first = -1;
    rlist[i].second.second = 0;
  }
  for (j = 0; j < c; j++) {
    clist[j].second.first = j;
    clist[j].first = -1;
    rlist[i].second.second = 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &x, &a, &temp);
    a -= 1;
    if (x == 1) {
      rlist[a].first = i;
      rlist[a].second.second = temp;
    } else {
      clist[a].first = i;
      clist[a].second.second = temp;
    }
  }
  sort(rlist, rlist + r);
  sort(clist, clist + c);
  i = 0;
  j = 0;
  while (i < r || j < c) {
    if (i == r) {
      for (x = 0; x < r; x++) {
        arr[x][clist[j].second.first] = clist[j].second.second;
      }
      j += 1;
    } else if (j == c) {
      for (x = 0; x < c; x++) {
        arr[rlist[i].second.first][x] = rlist[i].second.second;
      }
      i += 1;
    } else {
      if (rlist[i].first < clist[j].first) {
        for (x = 0; x < c; x++) {
          arr[rlist[i].second.first][x] = rlist[i].second.second;
        }
        i += 1;
      } else {
        for (x = 0; x < r; x++) {
          arr[x][clist[j].second.first] = clist[j].second.second;
        }
        j += 1;
      }
    }
  }
  cok();
  return 0;
}
