#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int id(int x, int y) { return (x - 1) * m + y; }
vector<pair<int, int> > v[2000010], rv[2000010];
int f[1010 * 1010], a[1010][1010], num[2000010], ans;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int find(int x) { return x == f[x] ? f[x] : f[x] = find(f[x]); }
int vis[1010][1010];
void add(int flag, vector<pair<int, int> >& vec) {
  int i, j;
  if (!vec.size()) return;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) vis[i][j] = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) f[id(i, j)] = id(i, j);
  for (auto p : vec) {
    int t = p.first, pos = p.second, tmp = 1;
    int x = pos / m + 1, y = pos - (x - 1) * m;
    if (!y) y += m, x--;
    vis[x][y] = 1;
    for (i = 0; i < 4; i++) {
      int tx = x + dx[i], ty = y + dy[i];
      if (tx > 0 && ty > 0 && tx <= n && ty <= m && vis[tx][ty])
        if (find(id(tx, ty)) != find(id(x, y)))
          f[find(id(tx, ty))] = f[find(id(x, y))], tmp--;
    }
    num[t] += tmp * flag;
  }
}
int main() {
  int i, j;
  scanf("%d%d%d", &n, &m, &q);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) v[0].push_back(make_pair(0, id(i, j)));
  for (i = 1; i <= q; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    int col = a[x][y];
    a[x][y] = c;
    if (c == col) continue;
    v[c].push_back(make_pair(i, id(x, y)));
    rv[col].push_back(make_pair(i, id(x, y)));
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) rv[a[i][j]].push_back(make_pair(q + 1, id(i, j)));
  for (i = 0; i <= 2000000; i++) reverse(rv[i].begin(), rv[i].end());
  for (i = 0; i <= 2000000; i++) add(1, v[i]);
  for (i = 0; i <= 2000000; i++) add(-1, rv[i]);
  ans += num[0];
  for (i = 1; i <= q; i++) printf("%d\n", ans += num[i]);
  return 0;
}
