#include <bits/stdc++.h>
using namespace std;
const int MAXQ = 2000005;
int N, M, Q;
vector<pair<int, int> > chg[305][305];
vector<tuple<int, int, int> > join[MAXQ];
vector<tuple<int, int, int> > rem[MAXQ];
vector<pair<int, int> > keep[MAXQ];
int par[300 * 300 + 5];
bool vis[305][305];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ans[MAXQ];
bool in_bounds(int x, int y) { return x >= 0 && x < N && y >= 0 & y < M; }
int find_parent(int x) {
  if (par[x] == x) return x;
  return par[x] = find_parent(par[x]);
}
bool merge(int a, int b) {
  a = find_parent(a), b = find_parent(b);
  if (a == b) return false;
  par[a] = b;
  return true;
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 1, x, y, c; i <= Q; i++) {
    scanf("%d%d%d", &x, &y, &c);
    chg[x - 1][y - 1].emplace_back(c, i);
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      if (chg[i][j].empty()) {
        keep[0].emplace_back(i, j);
        continue;
      }
      sort(chg[i][j].begin(), chg[i][j].end());
      rem[0].push_back(tuple<int, int, int>(chg[i][j][0].second, i, j));
      for (int k = 0; k < chg[i][j].size(); k++) {
        join[chg[i][j][k].first].push_back(
            tuple<int, int, int>(chg[i][j][k].second, i, j));
        if (k + 1 != chg[i][j].size())
          rem[chg[i][j][k].first].push_back(
              tuple<int, int, int>(chg[i][j][k + 1].second, i, j));
        else
          keep[chg[i][j][k].first].emplace_back(i, j);
      }
    }
  for (int c = 0; c < MAXQ; c++) {
    if (!join[c].empty()) {
      sort(join[c].begin(), join[c].end());
      for (int i = 0; i < N * M; i++) par[i] = i;
      for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++) vis[i][j] = false;
      for (tuple<int, int, int>& e : join[c]) {
        int idx, x, y;
        tie(idx, x, y) = e;
        int net = 1;
        vis[x][y] = true;
        for (int i = 0; i < 4; i++) {
          int x1 = x + dx[i], y1 = y + dy[i];
          if (in_bounds(x1, y1) && vis[x1][y1])
            net -= merge(x * M + y, x1 * M + y1);
        }
        ans[idx] += net;
      }
    }
    if (!rem[c].empty()) {
      sort(rem[c].begin(), rem[c].end());
      reverse(rem[c].begin(), rem[c].end());
      for (int i = 0; i < N * M; i++) par[i] = i;
      for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++) vis[i][j] = false;
      for (auto& p : keep[c]) {
        int x = p.first, y = p.second;
        vis[x][y] = true;
        for (int i = 0; i < 4; i++) {
          int x1 = x + dx[i], y1 = y + dy[i];
          if (in_bounds(x1, y1) && vis[x1][y1]) merge(x * M + y, x1 * M + y1);
        }
      }
      for (tuple<int, int, int>& e : rem[c]) {
        int idx, x, y;
        tie(idx, x, y) = e;
        int net = 1;
        vis[x][y] = true;
        for (int i = 0; i < 4; i++) {
          int x1 = x + dx[i], y1 = y + dy[i];
          if (in_bounds(x1, y1) && vis[x1][y1])
            net -= merge(x * M + y, x1 * M + y1);
        }
        ans[idx] -= net;
      }
    }
  }
  ans[0] = 1;
  for (int i = 1; i <= Q; i++) {
    ans[i] += ans[i - 1];
    printf("%d\n", ans[i]);
  }
  return 0;
}
