#include <bits/stdc++.h>
using namespace std;
int n, m, q;
const int maxn = 2e5 + 50;
int rk[maxn], fa[maxn];
int fnd(int x) { return (x == fa[x]) ? x : fa[x] = fnd(fa[x]); }
int link(int u, int v) {
  u = fnd(u);
  v = fnd(v);
  if (u == v) return 0;
  if (rk[u] < rk[v]) swap(u, v);
  fa[v] = u;
  if (rk[u] == rk[v]) rk[u]++;
  return 1;
}
vector<int> g[maxn];
int a[maxn];
void init() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = (0); i < (n * m); ++i) fa[i] = i;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m - 1); ++j) {
      int u = i * m + j, v = i * m + j + 1;
      g[u].push_back(v);
      g[v].push_back(u);
    }
  for (int j = (0); j < (m); ++j)
    for (int i = (0); i < (n - 1); ++i) {
      int u = i * m + j, v = (i + 1) * m + j;
      g[u].push_back(v);
      g[v].push_back(u);
    }
}
vector<pair<int, int> > add[2000005], del[2000005];
int d[maxn * 10];
void work(vector<pair<int, int> > &c, int op) {
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j)
      a[i * m + j] = 0, fa[i * m + j] = i * m + j, rk[i * m + j] = 1;
  for (auto t : c) {
    int u = t.first, id = t.second;
    int cur = 1;
    a[u] = 1;
    for (int v : g[u]) {
      if (a[v]) cur -= link(u, v);
    }
    d[id] += cur * op;
  }
}
void sol() {
  int mx = 1;
  for (int i = 0; i < q; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    x--;
    y--;
    int u = x * m + y;
    if (c == a[u]) continue;
    mx = c + 1;
    add[c].push_back(pair<int, int>(u, i));
    del[a[u]].push_back(pair<int, int>(u, i));
    a[u] = c;
  }
  for (int i = (0); i < (n * m); ++i) del[a[i]].push_back(pair<int, int>(i, q));
  for (int i = (0); i < (mx); ++i) reverse(del[i].begin(), del[i].end());
  for (int i = (0); i < (mx); ++i) work(add[i], 1);
  for (int i = (0); i < (mx); ++i) work(del[i], -1);
  int ans = 1;
  for (int i = (0); i < (q); ++i) ans += d[i], printf("%d\n", ans);
}
int main() {
  init();
  sol();
}
