#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
struct DSU {
  vector<int> p, sz;
  int componentCount;
  DSU(int n) : p(n, -1), sz(n, 0) { componentCount = 0; }
  void makeRoot(int u) {
    assert(p[u] == -1);
    p[u] = u;
    sz[u] = 1;
    componentCount++;
  }
  int parent(int u) {
    if (p[u] == u) return u;
    return p[u] = parent(p[u]);
  }
  bool unite(int u, int v) {
    u = parent(u);
    v = parent(v);
    if (u == v) return false;
    componentCount--;
    if (sz[u] < sz[v]) swap(u, v);
    p[v] = u;
    sz[u] += sz[v];
    return true;
  }
};
struct Ara {
  int n, m;
  vector<vector<int> > color;
  DSU dsu;
  Ara(int n, int m) : n(n), m(m), color(n, vector<int>(m, -1)), dsu(n * m) {}
  void unColor(int x, int y) {
    int u = encode(x, y);
    dsu.p[u] = -1;
    dsu.sz[u] = 0;
    color[x][y] = -1;
  }
  int encode(int x, int y) { return x * m + y; }
  int colorIt(int x, int y, int c) {
    int u = encode(x, y);
    if (color[x][y] == -1) {
      color[x][y] = c;
      dsu.makeRoot(u);
    } else {
      assert(color[x][y] == c);
      return dsu.componentCount;
    }
    for (int k = 0; k < 4; k++) {
      int _x = x + dx[k];
      int _y = y + dy[k];
      if (_x < 0 || _y < 0 || _x >= n || _y >= m) continue;
      int _u = encode(_x, _y);
      if (color[x][y] == color[_x][_y]) {
        dsu.unite(u, _u);
      }
    }
    return dsu.componentCount;
  }
};
const int MAXQ = 2e6 + 7;
int qx[MAXQ], qy[MAXQ], qc[MAXQ];
int ans[MAXQ];
int color[303][303];
int rc[MAXQ];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    cin >> qx[i] >> qy[i] >> qc[i];
    qx[i]--;
    qy[i]--;
  }
  for (int i = 1; i <= q; i++) {
    int j = i;
    while (j + 1 <= q && qc[j + 1] == qc[j]) j++;
    Ara ara(n, m);
    for (int l = i; l <= j; l++) {
      rc[l] = -1;
      if (color[qx[l]][qy[l]] != qc[l]) {
        rc[l] = color[qx[l]][qy[l]];
        color[qx[l]][qy[l]] = qc[l];
        ara.colorIt(qx[l], qy[l], qc[l]);
      }
      ans[l] += ara.dsu.componentCount;
    }
    for (int l = i; l <= j; l++) {
      ara.unColor(qx[l], qy[l]);
    }
    ara.dsu.componentCount = 0;
    for (int x = 0; x < n; x++) {
      for (int y = 0; y < m; y++) {
        if (color[x][y] == qc[i]) continue;
        ara.colorIt(x, y, color[x][y]);
      }
    }
    for (int l = j; l >= i; l--) {
      ans[l] += ara.dsu.componentCount;
      if (rc[l] != -1) ara.colorIt(qx[l], qy[l], rc[l]);
    }
    i = j;
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
