#include <bits/stdc++.h>
using namespace std;
const int maxn = 305, maxq = 2000005;
int n, m, q, a[maxn][maxn], upd[maxn * maxn + maxn], rnk[maxn * maxn + maxn],
    ans[maxq], mo[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}, tt;
int par[maxn * maxn + maxn], lst[maxn * maxn + maxn];
vector<pair<pair<int, int>, int>> v;
inline int gv(int x, int y) { return (x - 1) * m + y - 1; }
inline int ro(int x, int y) {
  int b = gv(x, y);
  if (lst[b] != tt) lst[b] = tt, par[b] = b;
  while (b != par[b]) {
    par[b] = par[par[b]];
    b = par[b];
  }
  return b;
}
inline void merge(int a, int b) {
  if (lst[a] != tt) lst[a] = tt, par[a] = a, rnk[a] = 1;
  if (lst[b] != tt) lst[b] = tt, par[b] = b, rnk[b] = 1;
  if (rnk[a] < rnk[b]) swap(a, b);
  rnk[a] = max(rnk[a], rnk[b] + 1);
  par[b] = a;
}
inline void solve(int col) {
  int cc = 0;
  tt++;
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= m; k++) {
      int t = gv(i, k);
      cc += (a[i][k] != col && upd[t] != col);
      if (a[i][k] == col || upd[t] == col) continue;
      for (int v = 0; v < 4; v++) {
        int nx = i + mo[v][0], ny = k + mo[v][1];
        if (nx >= 1 && ny >= 1 && nx <= n && ny <= m && a[nx][ny] == a[i][k] &&
            upd[gv(nx, ny)] != col) {
          int f = ro(nx, ny), s = ro(i, k);
          if (f == s) continue;
          merge(f, s);
          cc--;
        }
      }
    }
  }
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    int x = v[i].first.first, y = v[i].first.second, idx = v[i].second;
    ans[idx] = cc;
    if (upd[gv(x, y)] == col) {
      cc++;
      for (int k = 0; k < 4; k++) {
        int nx = x + mo[k][0], ny = y + mo[k][1];
        if (nx >= 1 && ny >= 1 && nx <= n && ny <= m && a[nx][ny] == a[x][y] &&
            upd[gv(nx, ny)] != col) {
          int f = ro(nx, ny), s = ro(x, y);
          if (f == s) continue;
          merge(f, s);
          cc--;
        }
      }
    }
    upd[gv(x, y)] = col - 1;
  }
  for (auto &ck : v) upd[gv(ck.first.first, ck.first.second)] = col;
  cc = 0;
  tt++;
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= m; k++) {
      int t = gv(i, k);
      cc += (a[i][k] == col && upd[t] != col);
      if (a[i][k] != col || upd[t] == col) continue;
      for (int v = 0; v < 4; v++) {
        int nx = i + mo[v][0], ny = k + mo[v][1];
        if (nx >= 1 && ny >= 1 && nx <= n && ny <= m && a[nx][ny] == a[i][k] &&
            upd[gv(nx, ny)] != col) {
          int f = ro(nx, ny), s = ro(i, k);
          if (f == s) continue;
          merge(f, s);
          cc--;
        }
      }
    }
  }
  for (auto &ck : v) {
    int x = ck.first.first, y = ck.first.second, idx = ck.second;
    if (upd[gv(x, y)] == col) {
      cc++;
      for (int i = 0; i < 4; i++) {
        int nx = x + mo[i][0], ny = y + mo[i][1];
        if (nx >= 1 && ny >= 1 && nx <= n && ny <= m && a[nx][ny] == col &&
            upd[gv(nx, ny)] != col) {
          int f = ro(nx, ny), s = ro(x, y);
          if (f == s) continue;
          merge(f, s);
          cc--;
        }
      }
      upd[gv(x, y)] = col - 1;
    }
    a[x][y] = col;
    ans[idx] += cc;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  int lst = -1;
  for (int _ = 1; _ <= q; _++) {
    int x, y, c;
    scanf(" %d %d %d", &x, &y, &c);
    if (lst != -1 && c != lst) solve(lst), v.clear();
    lst = c;
    if (a[x][y] != c && upd[gv(x, y)] != c)
      v.push_back(make_pair(make_pair(x, y), _)), upd[gv(x, y)] = c;
  }
  solve(lst);
  for (int i = 1; i <= q; i++) {
    if (ans[i] == 0) ans[i] = ans[i - 1];
    printf("%d\n", ans[i]);
  }
}
