#include <bits/stdc++.h>
using namespace std;
const int N = 305, M = 2000005, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <typename T>
void read(T &num) {
  num = 0;
  int ch = getchar();
  T fl = 1;
  while (!isdigit(ch) && ch != 45) ch = getchar();
  if (ch == 45) fl = -1, ch = getchar();
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch - 48);
    ch = getchar();
  }
  num *= fl;
}
template <typename T>
void write(T num) {
  static int buf[55];
  static int idx = 0;
  if (num == 0) {
    putchar(48);
    return;
  }
  if (num < 0) {
    putchar(45);
    num = -num;
  }
  while (num) {
    buf[idx++] = num % 10;
    num /= 10;
  }
  while (idx) putchar(buf[--idx] + 48);
}
int n, m, q, f[M * 2], num, id[N][N], a[N][N], ans[M], idx;
inline int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); }
struct Query {
  int x, y, cur, pre;
} qq[M];
inline void merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x != y) f[x] = y, --num;
}
inline void check(int x, int y) {
  for (int i = 0; i < 4; i++)
    if (a[x][y] == a[x + dx[i]][y + dy[i]])
      merge(id[x][y], id[x + dx[i]][y + dy[i]]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  read(n);
  read(m);
  read(q);
  int t1, t2, t3;
  for (int i = 1; i <= q; i++) {
    read(t1);
    read(t2);
    read(t3);
    qq[i] = {t1, t2, t3, a[t1][t2]};
    a[t1][t2] = t3;
  }
  ans[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;
  for (int i = 1; i <= q; i++) {
    if (qq[i].pre == qq[i].cur) continue;
    num = 1;
    a[qq[i].x][qq[i].y] = qq[i].cur;
    id[qq[i].x][qq[i].y] = ++idx;
    f[idx] = idx;
    check(qq[i].x, qq[i].y);
    ans[i] = num;
  }
  idx = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) id[i][j] = ++idx, f[idx] = idx;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) check(i, j);
  for (int i = q; i > 0; --i) {
    if (qq[i].pre == qq[i].cur) continue;
    num = 1;
    a[qq[i].x][qq[i].y] = qq[i].pre;
    id[qq[i].x][qq[i].y] = ++idx;
    f[idx] = idx;
    check(qq[i].x, qq[i].y);
    ans[i] -= num;
  }
  for (int i = 1; i <= q; i++)
    ans[i] += ans[i - 1], write(ans[i]), putchar('\n');
  return 0;
}
