#include <bits/stdc++.h>
using namespace std;
const int N = 305;
const int K = 2e6 + 5;
int n, m, q;
int p[N * N];
int sz[N * N];
int a[N][N];
int save[K][3];
int ans[K];
int cnt;
int o[K];
bool b[K];
int id(int x, int y) { return (x - 1) * m + y - 1; }
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
bool ok(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
void upd(int x, int y, int* v) {
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};
  (*v)++;
  for (int k = 0; k < 4; k++) {
    int tx = dx[k] + x;
    int ty = dy[k] + y;
    if (!ok(tx, ty)) continue;
    int idx = id(x, y), tidx = id(tx, ty);
    int fa = find(idx), tfa = find(tidx);
    if (a[x][y] == a[tx][ty] && fa != tfa) {
      (*v)--;
      if (sz[fa] >= sz[tfa]) {
        sz[fa] += sz[tfa];
        p[tfa] = fa;
      } else {
        sz[tfa] += sz[fa];
        p[fa] = tfa;
      }
    }
  }
}
int fall(int v) {
  int re = 0;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      int idx = id(x, y);
      p[idx] = idx, sz[idx] = 1;
    }
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      if (a[x][y] <= v) {
        upd(x, y, &re);
      }
    }
  return re;
}
void test() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << a[i][j] << ' ';
    cout << endl;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  int now = 0;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      int idx = id(x, y);
      p[idx] = idx, sz[idx] = 1;
    }
  for (int i = 1; i <= q; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    if (o[cnt] != c) {
      now = 0;
      o[++cnt] = c;
    }
    if (a[x][y] == cnt) {
      b[i] = 1;
      continue;
    }
    save[i][0] = x;
    save[i][1] = y;
    save[i][2] = a[x][y];
    int idx = id(x, y);
    p[idx] = idx, sz[idx] = 1;
    a[x][y] = cnt;
    upd(x, y, &now);
    ans[i] = now;
  }
  for (int i = q; i >= 1; i--) {
    if (b[i]) continue;
    int x = save[i][0], y = save[i][1], c = save[i][2];
    if (cnt == a[x][y]) {
      now = fall(--cnt);
    }
    ans[i] += now;
    int idx = id(x, y);
    p[idx] = idx, sz[idx] = 1;
    a[x][y] = c;
    upd(x, y, &now);
  }
  for (int i = 1; i <= q; i++)
    if (b[i]) ans[i] = ans[i - 1];
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
