#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
class UnionFind {
  vector<int> par, sz;
  vector<int> used;

 public:
  int cnt = 0;
  UnionFind() {}
  UnionFind(int n) {
    par = sz = vector<int>(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  void set(int x) {
    used.push_back(x);
    sz[x] = 1;
    cnt++;
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    cnt--;
    if (sz[x] > sz[y]) {
      par[y] = x;
      sz[x] += sz[y];
    } else {
      par[x] = y;
      sz[y] += sz[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sz[find(x)]; }
  void reset() {
    for (int i : used) {
      par[i] = i;
      sz[i] = 0;
    }
    used.clear();
    cnt = 0;
  }
};
int n, m, q;
int x[2100000], y[2100000], c[2100000];
int a[400][400];
struct st {
  int t, x, y;
};
vector<st> in[2100000], out[2100000];
int suml[2100000], sumr[2100000];
int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
UnionFind uf;
void solve(int C) {
  vector<st>&In = in[C], &Out = out[C];
  if (In.empty()) return;
  uf.reset();
  int prv = 0;
  for (auto p : In) {
    uf.set(p.x * m + p.y);
    for (int k = 0; k < 4; k++) {
      int nx = p.x + dx[k], ny = p.y + dy[k];
      if (0 <= nx && nx < n && 0 <= ny && ny < m && uf.size(nx * m + ny)) {
        uf.unite(p.x * m + p.y, nx * m + ny);
      }
    }
    suml[p.t] += uf.cnt - prv;
    prv = uf.cnt;
  }
  suml[Out[0].t] -= prv;
  reverse(Out.begin(), Out.end());
  uf.reset();
  prv = 0;
  for (auto p : Out) {
    uf.set(p.x * m + p.y);
    for (int k = 0; k < 4; k++) {
      int nx = p.x + dx[k], ny = p.y + dy[k];
      if (0 <= nx && nx < n && 0 <= ny && ny < m && uf.size(nx * m + ny)) {
        uf.unite(p.x * m + p.y, nx * m + ny);
      }
    }
    sumr[p.t - 1] += uf.cnt - prv;
    prv = uf.cnt;
  }
  sumr[Out.back().t - 1] -= prv;
}
int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      in[0].push_back({0, i, j});
    }
  unordered_set<int> col{0};
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &x[i], &y[i], &c[i]);
    x[i]--;
    y[i]--;
    col.insert(c[i]);
    if (a[x[i]][y[i]] != c[i]) {
      out[a[x[i]][y[i]]].push_back({i + 1, x[i], y[i]});
      in[c[i]].push_back({i + 1, x[i], y[i]});
      a[x[i]][y[i]] = c[i];
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      out[a[i][j]].push_back({q + 1, i, j});
    }
  uf = UnionFind(n * m);
  for (int i : col) solve(i);
  for (int i = 0; i < q; i++) suml[i + 1] += suml[i];
  for (int i = q; i > 0; i--) sumr[i - 1] += sumr[i];
  for (int i = 1; i <= q; i++) {
    printf("%d\n", suml[i] + sumr[i]);
  }
}
