#include <bits/stdc++.h>
using namespace std;
const int N = 305, M = 2e6 + 100;
int a[N][N], b[N][N];
pair<int, int> par[N][N], t[N][N];
struct {
  int x, y, c;
} Q[M];
int res[M], marked[M], lastc[M];
pair<int, int> P(int x, int y) {
  if (par[x][y] == make_pair(x, y)) return par[x][y];
  return par[x][y] = P(par[x][y].first, par[x][y].second);
}
bool Merge(int x1, int y1, int x2, int y2) {
  pair<int, int> p1 = P(x1, y1), p2 = P(x2, y2);
  if (p1 == p2) return 0;
  par[p1.first][p1.second] = p2;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = 1;
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> Q[i].x >> Q[i].y >> Q[i].c;
    Q[i].c++;
  }
  for (int i = 1; i <= q; i++) {
    int l = i, r = i;
    int c = Q[i].c;
    for (int j = i + 1; j <= q; j++) {
      if (Q[i].c != Q[j].c) break;
      r = j;
    }
    for (int x = 1; x <= n; x++) {
      for (int y = 1; y <= m; y++) {
        b[x][y] = a[x][y];
      }
    }
    int head = 0, other = 0;
    for (int j = l; j <= r; j++) {
      if (a[Q[j].x][Q[j].y] == c) continue;
      lastc[j] = a[Q[j].x][Q[j].y];
      a[Q[j].x][Q[j].y] = c;
      b[Q[j].x][Q[j].y] = 0;
      marked[j] = 1;
    }
    for (int x = 1; x <= n; x++) {
      for (int y = 1; y <= m; y++) {
        par[x][y] = {x, y};
        if (b[x][y] == 0) continue;
        int cc = 1;
        if (x > 1 && b[x][y] == b[x - 1][y]) {
          cc -= Merge(x, y, x - 1, y);
        }
        if (y > 1 && b[x][y] == b[x][y - 1]) {
          cc -= Merge(x, y, x, y - 1);
        }
        if (b[x][y] == c)
          head += cc;
        else
          other += cc;
      }
    }
    for (int x = 1; x <= n; x++)
      for (int y = 1; y <= m; y++) t[x][y] = par[x][y];
    for (int j = l; j <= r; j++) {
      int x = Q[j].x, y = Q[j].y;
      if (marked[j] == 0) {
        res[j] += head;
        continue;
      }
      head++;
      b[x][y] = c;
      if (x > 1 && b[x - 1][y] == c) head -= Merge(x, y, x - 1, y);
      if (y > 1 && b[x][y - 1] == c) head -= Merge(x, y, x, y - 1);
      if (x < n && b[x + 1][y] == c) head -= Merge(x, y, x + 1, y);
      if (y < m && b[x][y + 1] == c) head -= Merge(x, y, x, y + 1);
      res[j] += head;
    }
    for (int x = 1; x <= n; x++)
      for (int y = 1; y <= m; y++) par[x][y] = t[x][y];
    res[r] += other;
    for (int j = r; j > l; j--) {
      if (!marked[j]) {
        res[j - 1] += other;
        continue;
      }
      int x = Q[j].x, y = Q[j].y;
      assert(lastc[j] != c);
      b[x][y] = lastc[j];
      other++;
      if (x > 1 && b[x - 1][y] == b[x][y]) other -= Merge(x, y, x - 1, y);
      if (y > 1 && b[x][y - 1] == b[x][y]) other -= Merge(x, y, x, y - 1);
      if (x < n && b[x + 1][y] == b[x][y]) other -= Merge(x, y, x + 1, y);
      if (y < m && b[x][y + 1] == b[x][y]) other -= Merge(x, y, x, y + 1);
      res[j - 1] += other;
    }
    i = r;
  }
  for (int i = 1; i <= q; i++) {
    cout << res[i] << "\n";
  }
  return 0;
}
