#include <bits/stdc++.h>
using namespace std;
const int N = 306;
int a[N][N], b[N][N], k[N][N];
struct DSU {
  int par[N * N];
  vector<pair<int, int> > record;
  bool is_record = 0;
  void setup(int sz) { memset(par, -1, sizeof(par[0]) * (sz + 5)); }
  int FIND(int u) {
    if (par[u] == -1) return u;
    int nxt = FIND(par[u]);
    if (is_record && nxt != par[u]) {
      record.emplace_back(u, par[u]);
    }
    return par[u] = nxt;
  }
  int UNION(int u, int v) {
    if (FIND(u) == FIND(v)) return 0;
    if (is_record) {
      record.emplace_back(u, par[FIND(u)]);
    }
    par[FIND(u)] = FIND(v);
    return 1;
  }
  void revert() {
    for (int i = record.size() - 1; i >= 0; --i) {
      pair<int, int> p = record[i];
      par[p.first] = p.second;
    }
    record.clear();
  }
};
int n, m;
DSU dsu;
DSU side;
void solve(vector<pair<int, int> > qu, int c) {
  int z = qu.size();
  for (auto it = qu.rbegin(); it != qu.rend(); ++it) {
    auto& p = *it;
    b[p.first][p.second] = z--;
  }
  dsu.setup(n * m);
  side.setup(n * m);
  int merges = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i + 1 < n && a[i][j] == a[i + 1][j] && !b[i][j] && !b[i + 1][j]) {
        merges += dsu.UNION(i * m + j, (i + 1) * m + j);
      }
      if (j + 1 < m && a[i][j] == a[i][j + 1] && !b[i][j] && !b[i][j + 1]) {
        merges += dsu.UNION(i * m + j, i * m + (j + 1));
      }
    }
  }
  vector<int> extra;
  int ex = 0;
  for (int i = qu.size() - 1; i >= 0; --i) {
    auto p = qu[i];
    int x = p.first, y = p.second;
    extra.push_back(ex);
    if (b[x][y] != i + 1) {
      continue;
    }
    if (x > 0 && a[x][y] == a[x - 1][y] &&
        (b[x - 1][y] > i + 1 || b[x - 1][y] == 0)) {
      ex += dsu.UNION(x * m + y, (x - 1) * m + y);
    }
    if (y > 0 && a[x][y] == a[x][y - 1] &&
        (b[x][y - 1] > i + 1 || b[x][y - 1] == 0)) {
      ex += dsu.UNION(x * m + y, x * m + (y - 1));
    }
    if (x + 1 < n && a[x][y] == a[x + 1][y] &&
        (b[x + 1][y] > i + 1 || b[x + 1][y] == 0)) {
      ex += dsu.UNION(x * m + y, (x + 1) * m + y);
    }
    if (y + 1 < m && a[x][y] == a[x][y + 1] &&
        (b[x][y + 1] > i + 1 || b[x][y + 1] == 0)) {
      ex += dsu.UNION(x * m + y, x * m + (y + 1));
    }
  }
  vector<int> conn;
  int ey = 0;
  for (int i = 0; i < qu.size(); ++i) {
    int x = qu[i].first, y = qu[i].second;
    if (!k[x][y]) {
      k[x][y] = 1;
      if (x > 0 && k[x][y] == k[x - 1][y]) {
        ey += side.UNION(x * m + y, (x - 1) * m + y);
      }
      if (y > 0 && k[x][y] == k[x][y - 1]) {
        ey += side.UNION(x * m + y, x * m + (y - 1));
      }
      if (x + 1 < n && k[x][y] == k[x + 1][y]) {
        ey += side.UNION(x * m + y, (x + 1) * m + y);
      }
      if (y + 1 < m && k[x][y] == k[x][y + 1]) {
        ey += side.UNION(x * m + y, x * m + (y + 1));
      }
    }
    conn.push_back(ey);
  }
  reverse(extra.begin(), extra.end());
  for (int i = 0; i < extra.size(); ++i) {
    cout << n * m - merges - extra[i] - conn[i] << "\n";
  }
  for (auto& p : qu) {
    b[p.first][p.second] = 0;
    k[p.first][p.second] = 0;
    a[p.first][p.second] = c;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int q;
  cin >> n >> m >> q;
  int lc = -1;
  vector<pair<int, int> > cur;
  for (int i = 1; i <= q; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    --x;
    --y;
    if (c != lc) {
      solve(cur, lc);
      cur.clear();
      lc = c;
    }
    cur.emplace_back(x, y);
  }
  solve(cur, lc);
  return 0;
}
