#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
pair<int, int> fa[305][305], fa0[305][305];
pair<int, int> findR(int x, int y) {
  if (fa[x][y].first == x && fa[x][y].second == y)
    return fa[x][y];
  else
    return fa[x][y] = findR(fa[x][y].first, fa[x][y].second);
}
bool merge(int x, int y, int x1, int y1) {
  if (findR(x, y) == findR(x1, y1)) return 0;
  fa[findR(x, y).first][findR(x, y).second] = findR(x1, y1);
  return 1;
}
int q[2000006][4];
int ans[2000006];
int a[305][305];
int p[2000006], f[2000006];
void print() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cerr << a[i][j] << " ";
    cerr << endl;
  }
  cerr << endl;
}
void work(int l, int r) {
  int x, y, c, x1, y1, c1;
  for (int i = l; i <= r; i++) {
    x = q[i][0];
    y = q[i][1];
    c = q[i][2];
    q[i][3] = a[x][y];
    if (a[x][y] == c) continue;
    fa[x][y] = make_pair(x, y);
    a[x][y] = c;
    ++p[i];
    for (int k = 0; k < 4; k++) {
      x1 = x + dx[k];
      y1 = y + dy[k];
      if (x1 < 0 || x1 > N - 1 || y1 < 0 || y1 > M - 1 || a[x1][y1] != c)
        continue;
      if (merge(x, y, x1, y1)) --p[i];
    }
  }
  p[l - 1] = 0;
  for (int i = l; i <= r; i++) {
    p[i] += p[i - 1];
    ans[i] = ans[l - 1] + p[i];
  }
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  ans[0] = 1;
  int last = 1;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
    --q[i][0];
    --q[i][1];
    if (i > 1 && q[i][2] != q[i - 1][2]) {
      work(last, i - 1);
      last = i;
    }
  }
  work(last, Q);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      fa[i][j] = make_pair(i, j);
    }
  }
  int x, y, c, x1, y1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      x = i;
      y = j;
      c = a[x][y];
      for (int k = 0; k < 4; k++) {
        x1 = x + dx[k];
        y1 = y + dy[k];
        if (x1 < 0 || x1 > N - 1 || y1 < 0 || y1 > M - 1 || a[x1][y1] != c)
          continue;
        merge(x, y, x1, y1);
      }
    }
  }
  memset(p, 0, sizeof(p));
  for (int i = Q; i >= 1; i--) {
    x = q[i][0];
    y = q[i][1];
    c = q[i][3];
    if (a[x][y] == c) continue;
    a[x][y] = c;
    fa[x][y] = make_pair(x, y);
    --p[i];
    for (int k = 0; k < 4; k++) {
      x1 = x + dx[k];
      y1 = y + dy[k];
      if (x1 < 0 || x1 > N - 1 || y1 < 0 || y1 > M - 1 || a[x1][y1] != c)
        continue;
      if (merge(x, y, x1, y1)) ++p[i];
    }
  }
  for (int i = 1; i <= Q; i++) {
    p[i] += p[i - 1];
    ans[i] += p[i];
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
