#include <bits/stdc++.h>
using namespace std;
int n, m, q, x, y, c, a[310][310], mc, dif[2000010], fa[90010];
int fin(int x) { return fa[x] == x ? x : (fa[x] = fin(fa[x])); }
int in(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
int merge(int x, int y) {
  int u = fin(x), v = fin(y);
  if (u == v)
    return 0;
  else {
    fa[u] = v;
    return 1;
  }
}
const int N = 2e6 + 10;
vector<pair<int, int> > add[N], del[N];
void calc(vector<pair<int, int> >& v, int coef) {
  if (v.empty()) return;
  static int dx[] = {0, 0, 1, -1};
  static int dy[] = {1, -1, 0, 0};
  for (int i = (int)0; i < (int)n; ++i)
    for (int j = (int)0; j < (int)m; ++j) a[i][j] = 0;
  for (int i = (int)0; i < (int)n * m; ++i) fa[i] = i;
  for (auto& p : v) {
    int x = p.first / m, y = p.first % m;
    a[x][y] = 1;
    int r = 1;
    for (int i = (int)0; i < (int)4; ++i) {
      int nx = x + dx[i], ny = y + dy[i];
      if (in(nx, ny) && a[nx][ny] == 1) {
        r -= merge(x * m + y, nx * m + ny);
      }
    }
    dif[p.second] += r * coef;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> q;
  memset(a, 0, sizeof(a));
  memset(dif, 0, sizeof(dif));
  for (int i = (int)0; i < (int)q; ++i) {
    cin >> x >> y >> c;
    --x, --y;
    if (c == a[x][y]) continue;
    add[c].emplace_back(x * m + y, i);
    del[a[x][y]].emplace_back(x * m + y, i);
    a[x][y] = c;
    mc = c;
  }
  for (int x = (int)0; x < (int)n; ++x)
    for (int y = (int)0; y < (int)m; ++y)
      del[a[x][y]].emplace_back(x * m + y, q);
  for (int i = (int)0; i < (int)mc + 1; ++i)
    reverse(del[i].begin(), del[i].end());
  for (int i = (int)0; i < (int)mc + 1; ++i) calc(add[i], 1);
  for (int i = (int)0; i < (int)mc + 1; ++i) calc(del[i], -1);
  int cur = 1;
  for (int i = (int)0; i < (int)q; ++i) {
    cur += dif[i];
    cout << cur << '\n';
  }
  return 0;
}
