#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int f[2090105];
int a[305][305];
int ans[2000005];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
struct node {
  int x, y, z, pre;
} c[2000005];
int find(int now) {
  if (f[now] == now) return now;
  return f[now] = find(f[now]);
}
int g(int x, int y) { return (x - 1) * m + y; }
int T;
int main() {
  scanf("%d%d%d", &n, &m, &q);
  T = n * m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) f[g(i, j)] = g(1, 1);
  for (int i = 1; i <= q; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    c[i].x = x;
    c[i].y = y;
    c[i].z = z;
    c[i].pre = a[x][y];
    if (a[x][y] != z)
      a[x][y] = z, f[g(x, y)] = ++T, f[T] = T;
    else
      continue;
    for (int j = 0; j < 4; j++) {
      int nx = x + dx[j], ny = y + dy[j];
      if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] != a[x][y])
        continue;
      int u = find(g(x, y)), v = find(g(nx, ny));
      if (u != v) {
        f[v] = u;
        ans[i]--;
      }
    }
  }
  memset(f, 0, sizeof(f));
  T = n * m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) f[g(i, j)] = g(i, j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] != a[i][j])
          continue;
        int u = find(g(i, j)), v = find(g(nx, ny));
        if (u != v) {
          f[v] = u;
        }
      }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) find(g(i, j));
  for (int i = q; i >= 1; i--) {
    int x = c[i].x, y = c[i].y;
    if (a[x][y] != c[i].pre)
      a[x][y] = c[i].pre, f[g(x, y)] = ++T, f[T] = T;
    else
      continue;
    for (int j = 0; j < 4; j++) {
      int nx = x + dx[j], ny = y + dy[j];
      if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] != a[x][y])
        continue;
      int u = find(g(x, y)), v = find(g(nx, ny));
      if (u != v) {
        f[v] = u;
        ans[i]++;
      }
    }
  }
  int t = 1;
  for (int i = 1; i <= q; i++) t += ans[i], printf("%d\n", t);
}
