#include <bits/stdc++.h>
using namespace std;
long long mod = (1000000007LL);
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
inline pair<int, int> operator+(pair<int, int> A, pair<int, int> B) {
  return pair<int, int>(A.first + B.first, A.second + B.second);
}
inline pair<int, int> operator-(pair<int, int> A, pair<int, int> B) {
  return pair<int, int>(A.first - B.first, A.second - B.second);
}
inline long long mult(long long a, long long b) { return (a * b) % mod; }
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int n, m, q, pai[2000010], peso[2000010], id[330][330], cnt, cor[330][330],
    sz[2000010], ans[2000010];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int X[2000010], Y[2000010], C[2000010];
int vis[330][330];
vector<int> rem[2000010], add[2000010];
int Find(int x) {
  if (x == pai[x]) return x;
  return pai[x] = Find(pai[x]);
}
void join(int a, int b) {
  a = Find(a), b = Find(b);
  if (a == b) return;
  if (peso[a] <= peso[b]) swap(a, b);
  pai[b] = a;
  if (peso[a] == peso[b]) peso[a]++;
  sz[a] += sz[b];
}
void ins(int cor) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      vis[i][j] = 0, pai[id[i][j]] = id[i][j], peso[id[i][j]] = id[i][j];
  int comp = 0;
  for (auto w : add[cor]) {
    int x = X[w], y = Y[w];
    int cara = 1;
    comp++;
    vis[x][y] = 1;
    for (int p = 0; p < 4; p++) {
      int a = x + dx[p], b = y + dy[p];
      if (a < 1 or b < 1 or a > n or b > m or !vis[a][b]) continue;
      int u = id[x][y], v = id[a][b];
      if (Find(u) != Find(v)) comp--, cara--;
      join(u, v);
    }
    ans[w] += cara;
  }
}
vector<pair<int, int> > pos[2000010];
void erase(int color) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      vis[i][j] = 0, pai[id[i][j]] = id[i][j], peso[id[i][j]] = id[i][j];
  for (auto w : pos[color]) {
    int i = w.first, j = w.second;
    if (cor[i][j] == color) {
      vis[i][j] = 1;
      for (int p = 0; p < 4; p++) {
        int a = i + dx[p], b = j + dy[p];
        if (a < 1 or b < 1 or a > n or b > m or !vis[a][b]) continue;
        int u = id[i][j], v = id[a][b];
        join(u, v);
      }
    }
  }
  reverse(begin(rem[color]), end(rem[color]));
  for (auto w : rem[color]) {
    int x = X[w], y = Y[w];
    int cara = 1;
    vis[x][y] = 1;
    for (int p = 0; p < 4; p++) {
      int a = x + dx[p], b = y + dy[p];
      if (a < 1 or b < 1 or a > n or b > m or !vis[a][b]) continue;
      int u = id[x][y], v = id[a][b];
      if (Find(u) != Find(v)) cara--;
      join(u, v);
    }
    ans[w] -= cara;
  }
}
void build(int x) {
  if (!max({(int)(pos[x]).size(), (int)(add[x]).size(), (int)(rem[x]).size()}))
    return;
  ins(x);
  erase(x);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) id[i][j] = (++cnt);
  int cores = 0;
  for (int i = 1; i <= q; i++) {
    cin >> X[i] >> Y[i] >> C[i];
    cores = max(cores, C[i]);
    if (C[i] != cor[X[i]][Y[i]]) {
      rem[cor[X[i]][Y[i]]].push_back(i);
      add[C[i]].push_back(i);
    }
    cor[X[i]][Y[i]] = C[i];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) pos[cor[i][j]].push_back({i, j});
  for (int c = 0; c <= cores; c++) build(c);
  for (int i = 1; i <= q; i++) {
    ans[i] += ans[i - 1];
    cout << ans[i] + 1 << '\n';
  }
}
