#include <bits/stdc++.h>
using namespace std;
namespace output {
void __(short x) { cout << x; }
void __(unsigned x) { cout << x; }
void __(int x) { cout << x; }
void __(long long x) { cout << x; }
void __(unsigned long long x) { cout << x; }
void __(double x) { cout << x; }
void __(long double x) { cout << x; }
void __(char x) { cout << x; }
void __(const char* x) { cout << x; }
void __(const string& x) { cout << x; }
void __(bool x) { cout << (x ? "true" : "false"); }
template <class S, class T>
void __(const pair<S, T>& x) {
  __(1 ? "(" : ""), __(x.first), __(1 ? ", " : " "), __(x.second),
      __(1 ? ")" : "");
}
template <class T>
void __(const vector<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class T>
void __(const set<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class T>
void __(const multiset<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class S, class T>
void __(const map<S, T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
void pr() { cout << "\n"; }
template <class S, class... T>
void pr(const S& a, const T&... b) {
  __(a);
  if (sizeof...(b)) __(' ');
  pr(b...);
}
}  // namespace output
using namespace output;
const int MN = 303, MM = 2e6 + 6;
int n, m, q, i, j, x, y, w, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1},
                            arr[MN][MN], lst[MN][MN], dn[MM], ans[MM],
                            ds[MN * MN];
int fnd(int x) { return ds[x] = ds[x] == x ? x : fnd(ds[x]); }
struct _ {
  int x, y, t;
};
vector<_> a[MM], b[MM];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  int lim = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) lst[i][j] = 1;
  for (i = 1; i <= q; i++) {
    scanf("%d%d%d", &x, &y, &w);
    lim = max(lim, w);
    if (i != 1) {
      a[arr[x][y]].push_back({x, y, lst[x][y]});
      b[arr[x][y]].push_back({x, y, i - 1});
      dn[arr[x][y]] = max(dn[arr[x][y]], lst[x][y]);
    }
    lst[x][y] = i;
    arr[x][y] = w;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      a[arr[i][j]].push_back({i, j, lst[i][j]});
      b[arr[i][j]].push_back({i, j, q});
      dn[arr[i][j]] = max(dn[arr[i][j]], lst[i][j]);
    }
  }
  for (j = 0; j <= lim; j++) {
    if (a[j].empty()) continue;
    sort(a[j].begin(), a[j].end(), [](_ i, _ j) { return i.t < j.t; });
    sort(b[j].begin(), b[j].end(), [](_ i, _ j) { return i.t > j.t; });
    int ct = 1, cur = 0;
    for (i = 1; i <= n; i++) {
      for (int k = 1; k <= m; k++) {
        ds[(i - 1) * m + k] = (i - 1) * m + k;
        arr[i][k] = 0;
      }
    }
    for (auto v : a[j]) {
      ans[ct] += cur;
      ans[min(v.t - 1, dn[j]) + 1] -= cur;
      ct = min(v.t - 1, dn[j]) + 1;
      if (arr[v.x][v.y]) continue;
      cur++;
      int id = (v.x - 1) * m + v.y;
      arr[v.x][v.y] = 1;
      for (i = 0; i < 4; i++) {
        int nx = v.x + dx[i], ny = v.y + dy[i];
        if (!arr[nx][ny]) continue;
        int ot = (nx - 1) * m + ny;
        if (fnd(id) != fnd(ot)) ds[fnd(id)] = fnd(ot), cur--;
      }
    }
    ans[ct] += cur;
    ans[dn[j] + 1] -= cur;
    for (i = 1; i <= n; i++) {
      for (int k = 1; k <= m; k++) {
        ds[(i - 1) * m + k] = (i - 1) * m + k;
        arr[i][k] = 0;
      }
    }
    ct = q, cur = 0;
    for (auto v : b[j]) {
      ans[ct + 1] -= cur;
      ans[max(v.t, dn[j]) + 1] += cur;
      ct = max(v.t, dn[j]);
      if (arr[v.x][v.y]) continue;
      cur++;
      int id = (v.x - 1) * m + v.y;
      arr[v.x][v.y] = 1;
      for (i = 0; i < 4; i++) {
        int nx = v.x + dx[i], ny = v.y + dy[i];
        if (!arr[nx][ny]) continue;
        int ot = (nx - 1) * m + ny;
        if (fnd(id) != fnd(ot)) ds[fnd(id)] = fnd(ot), cur--;
      }
    }
    ans[ct + 1] -= cur;
    ans[dn[j] + 1] += cur;
  }
  for (i = 1; i <= q; i++) ans[i] += ans[i - 1], printf("%d\n", ans[i]);
  return 0;
}
