#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MAXN = (int)2e6 + 5;
long long n, m, q;
vector<pair<int, int> > renk[MAXN];
vector<pair<int, int> > ters[MAXN];
int grid[100005];
int par[100005];
int ans[MAXN];
int find_set(int a) {
  if (par[a] == a) return a;
  return par[a] = find_set(par[a]);
}
int merg(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (par[a] == par[b]) {
    return 0;
  }
  par[a] = b;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    int idx = x * m + y;
    renk[c].push_back({idx, i});
    ters[grid[idx]].push_back({idx, i});
    grid[idx] = c;
  }
  int sz = n * m;
  for (int i = 0; i < sz; i++) {
    ters[grid[i]].push_back({i, q});
  }
  for (int i = 0; i < MAXN; i++) {
    if (renk[i].empty() && ters[i].empty()) continue;
    for (int j = 0; j < sz; j++) {
      par[j] = j;
      grid[j] = mod;
    }
    int cc = 0;
    for (pair<int, int> up : renk[i]) {
      int idx = up.first;
      int yer = up.second;
      if (grid[idx] == i) continue;
      grid[idx] = i;
      cc = 1;
      if (idx >= m && grid[idx - m] == i) {
        cc -= merg(idx, idx - m);
      }
      if (idx % m != 0 && grid[idx - 1] == i) {
        cc -= merg(idx, idx - 1);
      }
      if (idx % m != m - 1 && grid[idx + 1] == i) {
        cc -= merg(idx, idx + 1);
      }
      if (idx < sz - m && grid[idx + m] == i) {
        cc -= merg(idx, idx + m);
      }
      ans[yer] += cc;
    }
    for (int j = 0; j < sz; j++) {
      par[j] = j;
      grid[j] = mod;
    }
    reverse(ters[i].begin(), ters[i].end());
    cc = 0;
    for (pair<int, int> up : ters[i]) {
      int idx = up.first;
      int yer = up.second;
      if (grid[idx] == i) continue;
      grid[idx] = i;
      cc = 1;
      if (idx >= m && grid[idx - m] == i) {
        cc -= merg(idx, idx - m);
      }
      if (idx % m != 0 && grid[idx - 1] == i) {
        cc -= merg(idx, idx - 1);
      }
      if (idx % m != m - 1 && grid[idx + 1] == i) {
        cc -= merg(idx, idx + 1);
      }
      if (idx < sz - m && grid[idx + m] == i) {
        cc -= merg(idx, idx + m);
      }
      ans[yer] -= cc;
    }
  }
  int gen = 1;
  for (int i = 0; i < q; i++) {
    gen += ans[i];
    cout << gen << '\n';
  }
}
