#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 305;
const int maxm = 2e6 + 5;
const long long mod = 998244353;
int n, m, q;
int col[maxn][maxn];
int x[maxm], y[maxm], c[maxm], d[maxm];
vector<int> g[maxm][2];
int ans[maxm];
int row[4] = {-1, 1, 0, 0};
int co[4] = {0, 0, -1, 1};
void init() {
  d[1] = 1;
  for (int i = 2; i <= q; i++)
    if (c[i] == c[i - 1])
      d[i] = d[i - 1];
    else
      d[i] = d[i - 1] + 1;
  memset(col, 0, sizeof(col));
  for (int i = 1; i <= q; i++) {
    if (col[x[i]][y[i]] == d[i])
      continue;
    else {
      g[col[x[i]][y[i]]][1].push_back(i);
      g[d[i]][0].push_back(i);
      col[x[i]][y[i]] = d[i];
    }
  }
}
struct Dsu {
  int pre[90005];
  int find(int u) {
    if (pre[u] == u) return u;
    return pre[u] = find(pre[u]);
  }
  void join(int x, int y) {
    int fx = find(x);
    int fy = find(y);
    if (fx != fy) pre[fx] = fy;
  }
} dsu;
int ch(int x, int y) { return (x - 1) * m + y; }
bool ok(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
void add(int i) {
  for (auto u : g[i][0]) {
    int z = ch(x[u], y[u]);
    col[x[u]][y[u]] = 0;
    dsu.pre[z] = z;
  }
  for (auto u : g[i][0]) {
    int z = ch(x[u], y[u]);
    col[x[u]][y[u]] = i;
    ans[u]++;
    for (int j = 0; j <= 3; j++) {
      int nx = x[u] + row[j];
      int ny = y[u] + co[j];
      int nz = ch(nx, ny);
      if (!ok(nx, ny)) continue;
      if (col[nx][ny] == i) {
        int fx = dsu.find(z);
        int fy = dsu.find(nz);
        if (fx != fy) dsu.join(nz, z), ans[u]--;
      }
    }
  }
}
void change(int i) {
  if (i == 0) {
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= m; k++) {
        int z = ch(j, k);
        col[j][k] = -1;
        dsu.pre[z] = z;
      }
  }
  for (auto u : g[i][0]) {
    int z = ch(x[u], y[u]);
    col[x[u]][y[u]] = -1;
    dsu.pre[z] = z;
  }
  for (auto u : g[i][1]) col[x[u]][y[u]] = -2;
  if (i == 0) {
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= m; k++) {
        if (col[j][k] == -2) continue;
        col[j][k] = i;
        int z = ch(j, k);
        for (int p = 0; p <= 3; p++) {
          int nx = j + row[p];
          int ny = k + co[p];
          int nz = ch(nx, ny);
          if (!ok(nx, ny)) continue;
          if (col[nx][ny] == i) {
            int fx = dsu.find(z);
            int fy = dsu.find(nz);
            if (fx != fy) dsu.join(nz, z);
          }
        }
      }
  }
  for (auto u : g[i][0]) {
    if (col[x[u]][y[u]] == -2) continue;
    col[x[u]][y[u]] = i;
    int z = ch(x[u], y[u]);
    for (int j = 0; j <= 3; j++) {
      int nx = x[u] + row[j];
      int ny = y[u] + co[j];
      int nz = ch(nx, ny);
      if (!ok(nx, ny)) continue;
      if (col[nx][ny] == i) {
        int fx = dsu.find(z);
        int fy = dsu.find(nz);
        if (fx != fy) dsu.join(nz, z);
      }
    }
  }
}
void del(int i) {
  int siz = g[i][1].size();
  for (int k = siz - 1; k >= 0; k--) {
    int u = g[i][1][k];
    int z = ch(x[u], y[u]);
    col[x[u]][y[u]] = i;
    ans[u]--;
    for (int j = 0; j <= 3; j++) {
      int nx = x[u] + row[j];
      int ny = y[u] + co[j];
      int nz = ch(nx, ny);
      if (!ok(nx, ny)) continue;
      if (col[nx][ny] == i) {
        int fx = dsu.find(z);
        int fy = dsu.find(nz);
        if (fx != fy) dsu.join(nz, z), ans[u]++;
      }
    }
  }
}
void solve() {
  memset(ans, 0, sizeof(ans));
  ans[0] = 1;
  for (int i = 0; i <= d[q]; i++) {
    add(i);
    change(i);
    del(i);
  }
  for (int i = 1; i <= q; i++) ans[i] += ans[i - 1];
  for (int i = 1; i <= q; i++) printf("%d", ans[i]), puts("");
}
int main() {
  scanf("%d%d", &n, &m), scanf("%d", &q);
  for (int i = 1; i <= q; i++) scanf("%d%d", &x[i], &y[i]), scanf("%d", &c[i]);
  init();
  solve();
  return 0;
}
