#include <bits/stdc++.h>
template <typename _Tp>
inline void red(_Tp &x) {
  x = 0;
  bool fg = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fg ^= 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (_Tp)(ch ^ 48), ch = getchar();
  if (fg) x = -x;
}
using namespace std;
const int N = 305;
const int M = 90010;
const int Q = 2000010 + 300 * 300 * 2;
const int fig[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int a[N][N], n, m, q;
int ans[Q];
int far[M], tmpcnt;
bool vs[N][N];
void init() {
  for (int i = 1; i <= n * m; ++i) far[i] = i;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) vs[i][j] = 0;
  tmpcnt = 0;
}
int find(int u) { return u == far[u] ? u : far[u] = find(far[u]); }
void ut(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  far[u] = v;
  --tmpcnt;
}
struct pp {
  int x, y, ts;
};
int maxc;
vector<pp> col[Q];
bool eqlst[Q];
void Add(int x, int y) {
  tmpcnt++;
  for (int k = 0; k < 4; ++k) {
    int tx = x + fig[k][0], ty = y + fig[k][1];
    if (tx < 1 || ty < 1 || tx > n || ty > m) continue;
    if (vs[tx][ty]) {
      ut(((x - 1) * m + y), ((tx - 1) * m + ty));
    }
  }
  vs[x][y] = 1;
}
void ansadd(int l, int r, int v) {
  if (l > r) return;
  assert(l <= r);
  assert(l >= 0);
  assert(r + 1 < Q);
  ans[l] += v;
  ans[r + 1] -= v;
}
int curc, tid;
void upd(int x, int y, int c) {
  ++tid;
  if (a[x][y] == c) {
    eqlst[tid] = 1;
    return;
  }
  if (curc != c) {
    col[curc].push_back(pp{-1, -1, tid - 1});
    curc = c;
  }
  if (a[x][y] >= 0) col[a[x][y]].push_back(pp{x, y, tid - 1});
  col[c].push_back(pp{x, y, tid});
  a[x][y] = c;
}
int main() {
  red(n);
  red(m);
  red(q);
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) upd(i, j, 0);
  for (int i = 1; i <= q; ++i) {
    int x, y, c;
    red(x);
    red(y);
    red(c);
    upd(x, y, c);
  }
  int maxc = curc + 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) upd(i, j, maxc);
  assert(maxc < Q);
  assert(tid < Q);
  for (int c = 0; c <= curc; ++c)
    if (!col[c].empty()) {
      init();
      for (int i = 0; i < col[c].size(); ++i) {
        if (col[c][i].x == -1) break;
        Add(col[c][i].x, col[c][i].y);
        ansadd(col[c][i].ts, col[c][i].ts, tmpcnt);
      }
      if (c == curc) break;
      init();
      for (int i = col[c].size() - 1; i >= 0; --i) {
        if (col[c][i].x == -1) break;
        Add(col[c][i].x, col[c][i].y);
        ansadd(col[c][i - 1].ts + 1, col[c][i].ts, tmpcnt);
      }
    }
  for (int i = 1; i <= tid; ++i) ans[i] += ans[i - 1];
  for (int i = 1; i <= tid; ++i)
    if (eqlst[i]) ans[i] = ans[i - 1];
  for (int i = n * m + 1; i <= n * m + q; ++i) printf("%d\n", ans[i]);
  return 0;
}
