#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> data;
  UnionFind(int n) { data.resize(n + 1, -1); }
  void clear() { data.assign(data.size(), -1); }
  void clear(int x) { data[x] = -1; }
  int find(int x) {
    if (data[x] < 0)
      return x;
    else
      return data[x] = find(data[x]);
  }
  int size(int x) { return -data[find(x)]; }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  bool same(int x, int y) {
    x = find(x);
    y = find(y);
    return x == y;
  }
};
int n, m, q, cmax;
int mat[400][400];
int ans[2000010];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
vector<int> c, d;
vector<array<int, 3>> p;
UnionFind uf(400 * 400);
bool in(int i, int j) { return 1 <= i && i <= n && 1 <= j && j <= m; }
int convert(int i, int j) {
  int ret = (i - 1) * m + j;
  return ret;
}
void add() {
  vector<array<int, 2>> cv[cmax];
  set<int> s;
  for (int i = 0; i < q; i++) {
    if (!i || c[i - 1] != c[i]) {
      if (i)
        for (auto &iter : cv[c[i - 1]]) {
          uf.clear(convert(iter[0], iter[1]));
        }
      for (auto &iter : cv[c[i]]) {
        int x = iter[0], y = iter[1];
        for (int t = 0; t < 4; t++) {
          if (mat[x + dx[t]][y + dy[t]] == c[i]) {
            uf.unite(convert(x + dx[t], y + dy[t]), convert(x, y));
          }
        }
      }
    }
    int u = c[i];
    int x = p[i][0], y = p[i][1], z = p[i][2];
    for (int t = 0; t < 4; t++) {
      if (!in(x + dx[t], y + dy[t])) continue;
      if (mat[x + dx[t]][y + dy[t]] == u) {
        s.insert(uf.find(convert(x + dx[t], y + dy[t])));
      }
    }
    if (u != mat[x][y]) ans[z] += 1 - s.size();
    d.emplace_back(mat[x][y]);
    mat[x][y] = c[i];
    for (int t = 0; t < 4; t++) {
      if (!in(x + dx[t], y + dy[t])) continue;
      if (mat[x + dx[t]][y + dy[t]] == u) {
        uf.unite(convert(x + dx[t], y + dy[t]), convert(x, y));
      }
    }
    cv[mat[x][y]].push_back({x, y});
    s.clear();
  }
}
void sub() {
  vector<array<int, 2>> cv[cmax];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cv[mat[i][j]].push_back({i, j});
    }
  }
  set<int> s;
  uf.clear();
  for (int i = 0; i < q; i++) {
    if (!i || d[p[i - 1][2]] != d[p[i][2]]) {
      if (i)
        for (auto &iter : cv[d[p[i - 1][2]]]) {
          uf.clear(convert(iter[0], iter[1]));
        }
      for (auto &iter : cv[d[p[i][2]]]) {
        int x = iter[0], y = iter[1];
        for (int t = 0; t < 4; t++) {
          if (mat[x + dx[t]][y + dy[t]] == d[p[i][2]]) {
            uf.unite(convert(x + dx[t], y + dy[t]), convert(x, y));
          }
        }
      }
    }
    int x = p[i][0], y = p[i][1], z = p[i][2];
    int u = d[z];
    for (int t = 0; t < 4; t++) {
      if (!in(x + dx[t], y + dy[t])) continue;
      if (mat[x + dx[t]][y + dy[t]] == u) {
        s.insert(uf.find(convert(x + dx[t], y + dy[t])));
      }
    }
    if (u != mat[x][y]) ans[z] -= 1 - s.size();
    mat[x][y] = u;
    for (int t = 0; t < 4; t++) {
      if (!in(x + dx[t], y + dy[t])) continue;
      if (mat[x + dx[t]][y + dy[t]] == u) {
        uf.unite(convert(x + dx[t], y + dy[t]), convert(x, y));
      }
    }
    cv[mat[x][y]].push_back({x, y});
    s.clear();
  }
}
void print() {
  for (int i = 0; i < q; i++) {
    if (i)
      ans[i] += ans[i - 1];
    else
      ans[i] += 1;
    cout << ans[i] << "\n";
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  set<int> cset;
  map<int, int> cm;
  for (int i = 0; i < q; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    p.push_back({x, y, i});
    c.emplace_back(r);
    cset.insert(r);
  }
  for (auto &x : cset) {
    int r = cm.size() + 1;
    cmax = r + 1;
    cm[x] = r;
  }
  for (int i = 0; i < q; i++) c[i] = cm[c[i]];
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      if (!in(i, j)) mat[i][j] = -1;
    }
  }
  add();
  auto pcmp = [&](array<int, 3> u, array<int, 3> v) {
    int i = u[2], j = v[2];
    if (d[i] != d[j])
      return d[i] > d[j];
    else
      return i > j;
  };
  sort(p.begin(), p.end(), pcmp);
  sub();
  print();
  return 0;
}
