#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> adj[200005];
int val[200005];
int res[2000005];
vector<pair<int, int> > on[2000005], off[2000005];
int cmp;
int p[200005];
int col[200005];
int find(int v) { return v == p[v] ? v : p[v] = find(p[v]); }
void merge(int v, int u) {
  v = find(v);
  u = find(u);
  if (v != u) {
    cmp--;
    p[v] = u;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int v = i * m + j;
      int u = (i - 1) * m + j;
      adj[v].push_back(u);
      adj[u].push_back(v);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      on[0].push_back({i * m + j, 0});
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      int v = i * m + j;
      int u = i * m + j - 1;
      adj[v].push_back(u);
      adj[u].push_back(v);
    }
  }
  for (int i = 1; i <= q; ++i) {
    int v, u, c;
    cin >> v >> u >> c;
    v--;
    u--;
    int t = v * m + u;
    if (val[t] == c) continue;
    on[c].push_back({t, i});
    off[val[t]].push_back({t, i});
    val[t] = c;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int t = i * m + j;
      off[val[t]].push_back({t, q + 1});
    }
  }
  for (int i = 0; i <= 2000000; ++i) {
    if (on[i].empty()) continue;
    for (auto& x : on[i]) p[x.first] = x.first;
    cmp = 0;
    for (auto& x : on[i]) {
      int dif = cmp;
      ++cmp;
      col[x.first] = 1;
      for (auto& y : adj[x.first]) {
        if (col[y] == 1) {
          merge(y, x.first);
        }
      }
      dif = cmp - dif;
      res[x.second] += dif;
    }
    for (auto& x : on[i]) col[x.first] = 0;
    reverse(off[i].begin(), off[i].end());
    for (auto& x : off[i]) p[x.first] = x.first;
    cmp = 0;
    for (auto& x : off[i]) {
      int dif = cmp;
      ++cmp;
      col[x.first] = 1;
      for (auto& y : adj[x.first]) {
        if (col[y] == 1) merge(y, x.first);
      }
      dif = cmp - dif;
      res[x.second] -= dif;
    }
    for (auto& x : off[i]) col[x.first] = 0;
  }
  for (int i = 1; i <= q; ++i) {
    res[i] += res[i - 1];
    cout << res[i] << '\n';
  }
}
