#include <bits/stdc++.h>
using namespace std;
const int M = 301;
const int N = 2e6 + 7;
const vector<int> dx = {0, 0, 1, -1};
const vector<int> dy = {1, -1, 0, 0};
namespace DSU {
vector<pair<int *, int>> mods;
int cnt = 0;
int p[N];
int rank[N];
int get(int v) {
  if (p[v] != v) {
    mods.emplace_back(&p[v], p[v]);
    p[v] = get(p[v]);
  }
  return p[v];
}
void merge(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) return;
  cnt--;
  if (rank[a] < rank[b]) swap(a, b);
  mods.emplace_back(&p[b], p[b]);
  p[b] = a;
  if (rank[a] == rank[b]) {
    mods.emplace_back(&rank[a], rank[a]);
    rank[a]++;
  }
}
void make(int v) {
  mods.emplace_back(&p[v], p[v]);
  mods.emplace_back(&rank[v], rank[v]);
  p[v] = v;
  rank[v] = 1;
  cnt++;
}
void init() {
  cnt = 0;
  fill(p, p + N, -1);
  fill(rank, rank + N, -1);
}
void clear() {
  cnt = 0;
  while (!mods.empty()) {
    *mods.back().first = mods.back().second;
    mods.pop_back();
  }
}
}  // namespace DSU
struct Query {
  int tp;
  int who;
  int pos;
  Query() {}
  Query(int tp_, int who_, int pos_) {
    tp = tp_;
    who = who_;
    pos = pos_;
  }
};
int n, m;
int ok(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
int add[N];
int a[M][M];
void solve(vector<Query> qr) {
  int last = 0;
  for (auto q : qr) {
    if (q.tp == 0) {
      int i, j;
      i = q.who / m;
      j = q.who % m;
      a[i][j] = 1;
      DSU::make(q.who);
      for (int k = 0; k < 4; k++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ok(ni, nj) && a[ni][nj]) {
          DSU::merge(q.who, ni * m + nj);
        }
      }
      add[q.pos] += (DSU::cnt - last);
      last = DSU::cnt;
    } else {
      break;
    }
  }
  for (auto q : qr) {
    if (q.tp == 0) {
    } else {
      int i, j;
      i = q.who / m;
      j = q.who % m;
      a[i][j] = 0;
    }
  }
  DSU::clear();
  for (auto q : qr) {
    if (a[q.who / m][q.who % m]) DSU::make(q.who);
  }
  for (auto q : qr) {
    int i, j;
    i = q.who / m;
    j = q.who % m;
    if (a[i][j]) {
      DSU::make(q.who);
      for (int k = 0; k < 4; k++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ok(ni, nj) && a[ni][nj]) {
          DSU::merge(q.who, ni * m + nj);
        }
      }
    }
  }
  reverse(qr.begin(), qr.end());
  last = DSU::cnt;
  for (auto q : qr) {
    if (q.tp == 0) {
    } else {
      int i, j;
      i = q.who / m;
      j = q.who % m;
      DSU::make(q.who);
      for (int k = 0; k < 4; k++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ok(ni, nj) && a[ni][nj]) {
          DSU::merge(q.who, ni * m + nj);
        }
      }
      add[q.pos] -= (DSU::cnt - last);
      last = DSU::cnt;
      a[i][j] = 1;
    }
  }
  DSU::clear();
  for (auto q : qr) {
    a[q.who / m][q.who % m] = 0;
  }
}
vector<Query> qs[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  DSU::init();
  int q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      qs[0].push_back(Query(0, i * m + j, 0));
    }
  }
  vector<vector<int>> ca(n, vector<int>(m));
  for (int i = 1; i <= q; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    if (ca[x][y] == c) continue;
    qs[ca[x][y]].push_back(Query(1, x * m + y, i));
    ca[x][y] = c;
    qs[ca[x][y]].push_back(Query(0, x * m + y, i));
  }
  for (int i = 0; i < N; i++) {
    if (!qs[i].empty()) {
      solve(qs[i]);
    }
  }
  int ans = 1;
  for (int i = 1; i <= q; i++) {
    ans += add[i];
    cout << ans << '\n';
  }
}
