#include <bits/stdc++.h>
using namespace std;
int ans[2000000 + 5], id[300 * 300 + 5],
    dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int cnt[2000000 + 5], sz[300 * 300 + 5], col[300 + 5][300 + 5], n, m, q;
bool vis[2000000 + 5];
pair<int, pair<int, int>> query[2000000 + 5];
int getId(int x, int y) { return (x - 1) * m + y; }
int root(int x) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
void u(int x, int y) {
  if (sz[x] < sz[y]) {
    swap(x, y);
  }
  id[y] = x;
  sz[x] += sz[y];
}
void merge(int x, int y) {
  int j, xx, yy, z, w;
  w = getId(x, y);
  for (j = 0; j < 4; ++j) {
    xx = x + dir[j][0];
    yy = y + dir[j][1];
    if (xx >= 1 and xx <= n and yy >= 1 and yy <= m) {
      if (col[xx][yy] == col[x][y]) {
        z = root(getId(xx, yy));
        w = root(w);
        if (z != w) {
          cnt[col[x][y]]--;
          u(w, z);
        }
      }
    }
  }
}
int init() {
  int i, j, ret = 0;
  for (i = 1; i <= n * m; ++i) {
    id[i] = i;
    sz[i] = 1;
  }
  for (i = 1; i <= 2000000; ++i) {
    cnt[i] = 0;
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      cnt[col[i][j]]++;
      ret++;
    }
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      ret -= cnt[col[i][j]];
      merge(i, j);
      ret += cnt[col[i][j]];
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, x, y, v, tot, w;
  cin >> n >> m >> q;
  for (i = 1; i <= q; ++i) {
    cin >> x >> y >> v;
    query[i] = {x, {y, col[x][y]}};
    ans[i] = cnt[v];
    if (col[x][y] == v) {
      continue;
    }
    col[x][y] = v;
    cnt[v]++;
    w = getId(x, y);
    id[w] = w;
    sz[w] = 1;
    merge(x, y);
    ans[i] = cnt[v];
  }
  tot = init();
  for (i = q; i >= 1; --i) {
    x = query[i].first;
    y = query[i].second.first;
    v = query[i].second.second;
    if (!vis[col[x][y]]) {
      vis[col[x][y]] = true;
      tot -= cnt[col[x][y]];
    }
    ans[i] += tot;
    if (col[x][y] == v) {
      continue;
    }
    col[x][y] = v;
    tot -= cnt[v];
    cnt[v]++;
    w = getId(x, y);
    id[w] = w;
    sz[w] = 1;
    merge(x, y);
    tot += cnt[v];
  }
  for (i = 1; i <= q; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
