#include <bits/stdc++.h>
const int MAXN = 310, MAXQ = 2000000 + 10, MAXC = 2000000 + 10;
int a[MAXN][MAXN];
std::vector<int> op[MAXN][MAXN];
int x[MAXQ], y[MAXQ], c[MAXQ];
int active[MAXQ], ans[MAXQ];
std::pair<int, int> d[4] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
const std::pair<int, int> zero(0, 0);
struct mpp {
  int n, m;
  std::unordered_map<int, int> a;
  void clear() { a.clear(); }
  mpp(int _n, int _m) : n(_n), m(_m) {}
  ~mpp() {}
  std::pair<int, int> operator[](const std::pair<int, int> &p) {
    auto ret = a.find(id(p.first, p.second));
    if (ret == a.end())
      return zero;
    else
      return std::pair<int, int>(ret->second / m + 1, ret->second % m + 1);
  }
  void set(const std::pair<int, int> &p, const std::pair<int, int> &q) {
    a[id(p.first, p.second)] = id(q.first, q.second);
  }
  int id(int x, int y) { return x * m + y - m - 1; }
};
int n, m, q;
struct ColorCom {
  mpp f;
  int cnt;
  ColorCom() : f(n, m), cnt(0) {}
  std::pair<int, int> getf(const std::pair<int, int> &x) {
    std::pair<int, int> fa = f[x];
    if (fa == x)
      return x;
    else {
      std::pair<int, int> root = getf(fa);
      f.set(x, root);
      return root;
    }
  }
  void confirm(const std::pair<int, int> &x) {
    if (f[x] == zero) {
      f.set(x, x);
      ++cnt;
    }
  }
  void link(std::pair<int, int> x, std::pair<int, int> y) {
    x = getf(x);
    y = getf(y);
    if (x != y) {
      f.set(x, y);
      --cnt;
    }
  }
  void clear() {
    cnt = 0;
    f.clear();
  }
};
bool legal(const std::pair<int, int> &a) {
  return a.first > 0 && a.second > 0 && a.first <= n && a.second <= m;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  ColorCom cur;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) op[i][j].push_back(0);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d%d", x + i, y + i, c + i);
    op[x[i]][y[i]].push_back(c[i]);
    a[x[i]][y[i]] = c[i];
    if (i > 1 && c[i] != c[i - 1]) cur.clear();
    cur.confirm(std::pair<int, int>(x[i], y[i]));
    for (std::pair<int, int> mov : d) {
      std::pair<int, int> nxt(x[i] + mov.first, y[i] + mov.second);
      if (legal(nxt) && a[nxt.first][nxt.second] == c[i])
        cur.link(std::pair<int, int>(x[i], y[i]), nxt);
    }
    active[i] = cur.cnt;
  }
  active[0] = 1;
  ColorCom *colors = new ColorCom[c[q] + 1];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      colors[a[i][j]].confirm(std::pair<int, int>(i, j));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      std::pair<int, int> p1(i, j);
      for (std::pair<int, int> mov : d) {
        std::pair<int, int> p2(i + mov.first, j + mov.second);
        if (legal(p2) && a[p2.first][p2.second] == a[i][j])
          colors[a[i][j]].link(p1, p2);
      }
    }
  int pre = c[q], sum = 0;
  for (int i = 0; i <= pre; ++i) sum += colors[i].cnt;
  for (int i = q; i > 0; --i) {
    while (pre >= c[i]) {
      sum -= colors[pre].cnt;
      --pre;
    }
    ans[i] = active[i] + sum;
    op[x[i]][y[i]].pop_back();
    a[x[i]][y[i]] = *std::prev(op[x[i]][y[i]].end());
    if (a[x[i]][y[i]] <= pre) {
      sum -= colors[a[x[i]][y[i]]].cnt;
      std::pair<int, int> p1(x[i], y[i]);
      colors[a[x[i]][y[i]]].confirm(p1);
      for (std::pair<int, int> mov : d) {
        std::pair<int, int> p2(x[i] + mov.first, y[i] + mov.second);
        if (legal(p2) && a[p2.first][p2.second] == a[x[i]][y[i]])
          colors[a[x[i]][y[i]]].link(p1, p2);
      }
      sum += colors[a[x[i]][y[i]]].cnt;
    }
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  delete[] colors;
}
