#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353, inv2 = (MOD + 1) / 2;
long double eps = 1e-6;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long double pi = acos(-1.0L);
struct node {
  int x, y, z;
} a[2222222];
vector<node> c[2222222];
vector<int> ans[2222222];
int t[2222222], fa[222222], b[333][333], d[333][333], num[333][333], n, m, q;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
int dsu(int k) {
  if (fa[k] != k) fa[k] = dsu(fa[k]);
  return fa[k];
}
int isok(int x, int y) {
  if (x > 0 && x <= n && y > 0 && y <= m) return 1;
  return 0;
}
void init() {
  n = read(), m = read(), q = read();
  for (int i = (int)1; i <= (int)q; i++)
    a[i].x = read(), a[i].y = read(), a[i].z = read();
}
void solve() {
  memset(b, 0, sizeof(b));
  int s = 0;
  for (int i = (int)1; i <= (int)n; i++)
    for (int j = (int)1; j <= (int)m; j++) num[i][j] = ++s;
  for (int i = (int)1; i <= (int)q; i++) {
    int x = a[i].x, y = a[i].y, z = a[i].z;
    if (b[x][y] == z) continue;
    c[b[x][y]].push_back((node){x, y, -1});
    ans[b[x][y]].push_back(0);
    b[x][y] = z;
    c[z].push_back((node){x, y, 1});
    ans[z].push_back(0);
  }
  for (int i = (int)0; i <= (int)a[q].z; i++) {
    ans[i].push_back(0);
    if (i == 0) {
      for (int j = (int)1; j <= (int)n * m; j++) fa[j] = 1;
      for (int j = (int)1; j <= (int)n; j++)
        for (int k = (int)1; k <= (int)m; k++) d[j][k] = 1;
    } else {
      for (int j = (int)1; j <= (int)n * m; j++) fa[j] = j;
      for (int j = (int)1; j <= (int)n; j++)
        for (int k = (int)1; k <= (int)m; k++) d[j][k] = 0;
    }
    for (int j = 0; j < c[i].size(); j++) {
      int x = c[i][j].x, y = c[i][j].y, op = c[i][j].z;
      if (op == -1) break;
      int t = 1;
      for (int k = (int)0; k <= (int)3; k++) {
        int tx = x + dx[k], ty = y + dy[k];
        if (isok(tx, ty) && d[tx][ty] == 1) {
          int p = dsu(num[x][y]), q = dsu(num[tx][ty]);
          if (p != q) {
            fa[q] = p;
            t--;
          }
        }
      }
      ans[i][j + 1] = t;
      d[x][y] = 1;
    }
    for (int j = (int)1; j <= (int)n * m; j++) fa[j] = j;
    for (int j = (int)1; j <= (int)n; j++)
      for (int k = (int)1; k <= (int)m; k++) d[j][k] = 0;
    for (int j = (int)1; j <= (int)n; j++)
      for (int k = (int)1; k <= (int)m; k++)
        if (b[j][k] == i) d[j][k] = 1;
    for (int j = (int)1; j <= (int)n; j++)
      for (int k = (int)1; k <= (int)m; k++)
        if (d[j][k]) {
          for (int op = (int)0; op <= (int)3; op++) {
            int x = j + dx[op], y = k + dy[op];
            if (isok(x, y) && d[x][y]) {
              int p = dsu(num[j][k]), q = dsu(num[x][y]);
              if (p != q) fa[q] = p;
            }
          }
        }
    for (int j = (int)c[i].size() - 1; j >= 0; j--) {
      int x = c[i][j].x, y = c[i][j].y, op = c[i][j].z;
      if (op == 1) break;
      int t = -1;
      for (int k = (int)0; k <= (int)3; k++) {
        int tx = x + dx[k], ty = y + dy[k];
        if (isok(tx, ty) && d[tx][ty] == 1) {
          int p = dsu(num[x][y]), q = dsu(num[tx][ty]);
          if (p != q) {
            fa[q] = p;
            t++;
          }
        }
      }
      ans[i][j + 1] = t;
      d[x][y] = 1;
    }
  }
  memset(b, 0, sizeof(b));
  memset(t, 0, sizeof(t));
  int res = 1;
  for (int i = (int)1; i <= (int)q; i++) {
    int x = a[i].x, y = a[i].y, z = a[i].z;
    if (b[x][y] == z) {
      printf("%d\n", res);
      continue;
    }
    t[b[x][y]]++;
    res += ans[b[x][y]][t[b[x][y]]];
    t[z]++;
    res += ans[z][t[z]];
    b[x][y] = z;
    printf("%d\n", res);
  }
}
int main() {
  init();
  solve();
  return 0;
}
