#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int N = 305, M = 2e6 + 5;
int n, m, q, cnt, tmp, a[N][N], id[N][N], res[M], fa[M << 1];
struct qwq {
  int x, y, a, b;
} t[M];
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
void merge(int x, int y) {
  int fx = get(x), fy = get(y);
  if (fx != fy) --tmp, fa[fx] = fy;
}
void update(int x, int y) {
  if (a[x][y] == a[x - 1][y]) merge(id[x][y], id[x - 1][y]);
  if (a[x][y] == a[x + 1][y]) merge(id[x][y], id[x + 1][y]);
  if (a[x][y] == a[x][y - 1]) merge(id[x][y], id[x][y - 1]);
  if (a[x][y] == a[x][y + 1]) merge(id[x][y], id[x][y + 1]);
}
void workpre() {
  for (int i = 1; i <= q; ++i) {
    int x = t[i].x, y = t[i].y;
    if (a[x][y] == t[i].a) continue;
    id[x][y] = ++cnt, fa[cnt] = cnt, tmp = 1;
    a[x][y] = t[i].a, update(x, y), res[i] += tmp;
  }
}
void worksuf() {
  for (int i = q; i >= 1; --i) {
    int x = t[i].x, y = t[i].y;
    if (a[x][y] == t[i].b) continue;
    id[x][y] = ++cnt, fa[cnt] = cnt, tmp = 1;
    a[x][y] = t[i].b, update(x, y), res[i] -= tmp;
  }
}
signed main() {
  read(n), read(m), read(q);
  for (int i = 1, x, y, z; i <= q; ++i) {
    read(x), read(y), read(z);
    t[i] = {x, y, z, a[x][y]}, a[x][y] = z;
  }
  res[0] = 1;
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) a[i][j] = 0;
  workpre();
  cnt = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) id[i][j] = ++cnt, fa[cnt] = cnt;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) update(i, j);
  worksuf();
  for (int i = 1; i <= q; ++i) res[i] += res[i - 1];
  for (int i = 1; i <= q; ++i) printf("%d\n", res[i]);
}
