#include <bits/stdc++.h>
using namespace std;
struct union_find {
  vector<int> parent;
  vector<int> size;
  int components = 0;
  union_find(int n = -1) {
    if (n >= 0) init(n);
  }
  void init(int n) {
    parent.resize(n + 1);
    size.assign(n + 1, 1);
    components = n;
    for (int i = 0; i <= n; i++) parent[i] = i;
  }
  int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (size[x] < size[y]) swap(x, y);
    parent[y] = x;
    size[x] += size[y];
    components--;
    return true;
  }
};
struct query {
  int16_t x, y;
  int c, lost;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> grid(N, vector<int>(M, 0));
  vector<query> queries(Q);
  for (query &qry : queries) {
    cin >> qry.x >> qry.y >> qry.c;
    qry.x--;
    qry.y--;
  }
  int C = queries.back().c;
  vector<int> counts(C + 1, 0);
  counts[0] = N * M;
  for (query &qry : queries) {
    qry.lost = grid[qry.x][qry.y];
    grid[qry.x][qry.y] = qry.c;
    counts[qry.c]++;
  }
  grid.assign(N, vector<int>(M, 0));
  vector<int> answers(Q, 1);
  vector<int> components(C + 1);
  components[0] = 1;
  auto &&to_index = [&](int row, int col) { return row * M + col; };
  vector<vector<int>> indices(C + 1);
  for (int q = 0; q < Q; q++) indices[queries[q].c].push_back(q);
  vector<int> forward_delta(Q, 0);
  for (int c = 1; c <= C; c++) {
    union_find UF(N * M);
    int add_components = 0, previous = 0;
    for (int q : indices[c]) {
      add_components++;
      query &qry = queries[q];
      assert(qry.c == c);
      if (qry.x > 0 && grid[qry.x - 1][qry.y] == c)
        add_components -=
            UF.unite(to_index(qry.x - 1, qry.y), to_index(qry.x, qry.y));
      if (qry.y > 0 && grid[qry.x][qry.y - 1] == c)
        add_components -=
            UF.unite(to_index(qry.x, qry.y - 1), to_index(qry.x, qry.y));
      if (qry.x < N - 1 && grid[qry.x + 1][qry.y] == c)
        add_components -=
            UF.unite(to_index(qry.x + 1, qry.y), to_index(qry.x, qry.y));
      if (qry.y < M - 1 && grid[qry.x][qry.y + 1] == c)
        add_components -=
            UF.unite(to_index(qry.x, qry.y + 1), to_index(qry.x, qry.y));
      grid[qry.x][qry.y] = c;
      forward_delta[q] += add_components - previous;
      previous = add_components;
    }
    components[c] = UF.components - (N * M - counts[c]);
  }
  for (int q = 0, delta = 0; q < Q; q++) {
    delta += forward_delta[q];
    answers[q] += delta;
  }
  vector<vector<int>> final_grid = grid;
  vector<int> final_counts(C + 1, 0);
  for (int row = 0; row < N; row++)
    for (int col = 0; col < M; col++) final_counts[grid[row][col]]++;
  indices.assign(C + 1, {});
  for (int q = Q - 1; q >= 0; q--) indices[queries[q].lost].push_back(q);
  vector<int> backward_delta(Q + 1, 0);
  for (int c = 0; c <= C; c++) {
    union_find UF(N * M);
    grid = final_grid;
    for (int row = 0; row < N; row++)
      for (int col = 0; col < M; col++)
        if (grid[row][col] == c) {
          if (row < N - 1 && grid[row + 1][col] == c)
            UF.unite(to_index(row + 1, col), to_index(row, col));
          if (col < M - 1 && grid[row][col + 1] == c)
            UF.unite(to_index(row, col + 1), to_index(row, col));
        }
    int delta = (UF.components - (N * M - final_counts[c])) - components[c];
    backward_delta[Q] += delta;
    int previous = delta;
    for (int q : indices[c]) {
      query &qry = queries[q];
      assert(qry.lost == c);
      delta -= UF.components;
      if (qry.x > 0 && grid[qry.x - 1][qry.y] == c)
        UF.unite(to_index(qry.x - 1, qry.y), to_index(qry.x, qry.y));
      if (qry.y > 0 && grid[qry.x][qry.y - 1] == c)
        UF.unite(to_index(qry.x, qry.y - 1), to_index(qry.x, qry.y));
      if (qry.x < N - 1 && grid[qry.x + 1][qry.y] == c)
        UF.unite(to_index(qry.x + 1, qry.y), to_index(qry.x, qry.y));
      if (qry.y < M - 1 && grid[qry.x][qry.y + 1] == c)
        UF.unite(to_index(qry.x, qry.y + 1), to_index(qry.x, qry.y));
      delta += UF.components;
      delta++;
      grid[qry.x][qry.y] = c;
      backward_delta[q] += delta - previous;
      previous = delta;
    }
  }
  for (int q = Q - 1, delta = 0; q >= 0; q--) {
    delta += backward_delta[q + 1];
    answers[q] += delta;
  }
  for (int q = 0; q < Q; q++) cout << answers[q] << '\n';
}
