#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
using namespace std;
template <typename T>
void Min(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void Max(T &a, T b) {
  a = max(a, b);
}
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 3e2 + 15;
const int M = 2e6 + 15;
int n, m, q, a[N][N];
int p[M], sz[M];
int C;
vector<pair<int, int> > add[M], del[M];
int ans[M];
bool used[N][N];
inline int find(int v) {
  while (v != p[v]) v = p[v] = p[p[v]];
  return v;
}
inline void unio(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    p[b] = a;
    sz[a] += sz[b];
  }
}
inline int ind(int i, int j) { return (i - 1) * m + j - 1; }
inline bool check(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }
inline void process(vector<pair<int, int> > &qs, int k) {
  for (pair<int, int> i : qs) {
    int flag = 1;
    int x = i.first / m, y = i.first % m;
    used[x][y] = true;
    for (int j = 0; j < 4; ++j) {
      int tox = x + dx[j], toy = y + dy[j];
      if (check(tox, toy) && used[tox][toy]) {
        int u = ind(x + 1, y + 1), v = ind(tox + 1, toy + 1);
        if (find(u) != find(v)) {
          --flag;
          unio(u, v);
        }
      }
    }
    ans[i.second] += k * flag;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= q; ++i) {
    int x, y, c;
    scanf("%d %d %d", &x, &y, &c);
    add[c].push_back({ind(x, y), i});
    del[a[x - 1][y - 1]].push_back({ind(x, y), i});
    a[x - 1][y - 1] = c;
    Max(C, c);
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) add[0].push_back({ind(i + 1, j + 1), 0});
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      del[a[i - 1][j - 1]].push_back({ind(i, j), q + 1});
  for (int t = 0; t <= C; ++t) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        used[i - 1][j - 1] = false;
        p[ind(i, j)] = ind(i, j), sz[ind(i, j)] = 1;
      }
    process(add[t], 1);
  }
  for (int t = 0; t <= C; ++t) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        used[i - 1][j - 1] = false;
        p[ind(i, j)] = ind(i, j), sz[ind(i, j)] = 1;
      }
    reverse(del[t].begin(), del[t].end());
    process(del[t], -1);
  }
  for (int i = 1; i <= q; ++i) {
    ans[i] += ans[i - 1];
    printf("%d\n", ans[i]);
  }
  return 0;
}
