#include <bits/stdc++.h>
using namespace std;
char buf[1 << 23], *p1 = buf, *p2 = buf;
int read() {
  static int res;
  static char op, f;
  for (f = 0,
      op = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2)
                ? EOF
                : *p1++);
       op > '9' || op < '0';
       op = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    f |= (op == '-');
  for (res = 0; op >= '0' && op <= '9';
       op = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    res = res * 10 + (op ^ 48);
  return f ? -res : res;
}
struct Node {
  int x, y, id;
  Node() {}
  Node(int _1, int _2, int _3) : x(_1), y(_2), id(_3) {}
};
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
vector<Node> q1[2000010], q2[2000010];
int Ans[2000010], col[310][310], fa[310 * 310], n, m, maxc, c;
int num(int x, int y) { return (x - 1) * m + y; }
bool check(int x, int y) { return x && y && x <= n && y <= m; }
void init() {
  for (int i = 1; i <= n * m; ++i) fa[i] = i;
}
int _f(int x) { return fa[x] == x ? x : fa[x] = _f(fa[x]); }
int _merge(int x, int y) {
  x = _f(x);
  y = _f(y);
  if (x == y) return 0;
  fa[y] = x;
  return 1;
}
signed main(int argc, char **argv) {
  n = read(), m = read(), c = read();
  for (int i = 1, x, y, k; i <= c; ++i) {
    x = read(), y = read(), k = read();
    q2[col[x][y]].push_back(Node(x, y, i));
    q1[col[x][y] = k].push_back(Node(x, y, i));
    maxc = k;
  }
  for (int i = 1, j; i <= n; ++i)
    for (j = 1; j <= m; ++j) q2[col[i][j]].push_back(Node(i, j, 0));
  memset(col, -1, sizeof col);
  for (int i = 0, j, k, len, nx, ny; i <= maxc; ++i)
    if ((len = q1[i].size()))
      for (j = 0, init(); j < len; ++j) {
        for (col[q1[i][j].x][q1[i][j].y] = i, ++Ans[q1[i][j].id], k = 0;
             nx = q1[i][j].x + dx[k], ny = q1[i][j].y + dy[k], k < 4; ++k)
          if (check(nx, ny && col[nx][ny] == i))
            Ans[q1[i][j].id] -=
                _merge(num(q1[i][j].x, q1[i][j].y), num(nx, ny));
      }
  memset(col, -1, sizeof col);
  for (int i = 0, j, k, len, nx, ny; i <= maxc; ++i)
    if ((len = q2[i].size()))
      for (j = len - 1, init(); ~j; --j) {
        for (col[q2[i][j].x][q2[i][j].y] = i, --Ans[q2[i][j].id], k = 0;
             nx = q2[i][j].x + dx[k], ny = q2[i][j].y + dy[k], k < 4; ++k)
          if (check(nx, ny) && col[nx][ny] == i)
            Ans[q2[i][j].id] +=
                _merge(num(q2[i][j].x, q2[i][j].y), num(nx, ny));
      }
  Ans[0] = 1;
  for (int i = 1; i <= c; ++i) printf("%d\n", Ans[i] += Ans[i - 1]);
  return 0;
}
