#include <bits/stdc++.h>
using namespace std;
const int nax = 333;
int a[nax][nax];
struct qq {
  int r;
  int c;
  int v;
};
int n, m, q;
bool exist[2 * 1000 * 1000 + 5];
int ans[2 * 1000 * 1000 + 5];
int res[2 * 1000 * 1000 + 5];
pair<int, int> par[nax][nax];
pair<int, int> f(int r, int c) {
  if (par[r][c] == make_pair(r, c)) return par[r][c];
  pair<int, int> p = par[r][c];
  return par[r][c] = f(p.first, p.second);
}
int u(int r1, int c1, int r2, int c2) {
  if (f(r1, c1) == f(r2, c2)) return 0;
  pair<int, int> p1 = f(r1, c1);
  pair<int, int> p2 = f(r2, c2);
  par[p1.first][p1.second] = p2;
  return 1;
}
int cur;
set<pair<int, int> > base[2 * 1000 * 1000 + 5];
set<int> ti[nax][nax];
vector<pair<int, pair<int, int> > > del[2 * 1000 * 1000 + 5];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  vector<qq> s;
  for (int i = 1; i <= q; i++) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    qq p;
    p.r = x;
    p.c = y;
    p.v = v;
    ti[x][y].insert(i);
    s.push_back(p);
    exist[v] = true;
  }
  vector<int> dx = {-1, 1, 0, 0};
  vector<int> dy = {0, 0, -1, 1};
  for (int i = 0; i < q; i++) {
    int l = i;
    int r = i;
    while (r + 1 < q && s[r + 1].v == s[r].v) r++;
    for (int j = l; j <= r; j++) {
      cur = 0;
      auto akt = s[j];
      int r = akt.r;
      int c = akt.c;
      int col = akt.v;
      if (a[r][c] == col) continue;
      a[r][c] = col;
      cur++;
      par[r][c] = make_pair(r, c);
      for (int z = 0; z < 4; z++) {
        int ar = r + dx[z];
        int ac = c + dy[z];
        if (ar < 1 || ar > n || ac < 1 || ac > m) continue;
        if (a[ar][ac] == col) cur -= u(r, c, ar, ac);
      }
      ans[j + 1] = cur;
    }
    set<pair<int, int> > done;
    set<pair<int, int> > cells;
    int col = s[l].v;
    for (int j = r; j >= l; j--) {
      auto akt = s[j];
      if (done.count(make_pair(akt.r, akt.c))) continue;
      done.insert(make_pair(akt.r, akt.c));
      auto it = ti[akt.r][akt.c].upper_bound(j + 1);
      if (it == ti[akt.r][akt.c].end()) {
        base[col].insert({akt.r, akt.c});
      } else {
        del[col].push_back(make_pair(*it, make_pair(akt.r, akt.c)));
      }
    }
    i = r;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) a[i][j] = 0;
  }
  for (int i = 0; i < 2 * 1000 * 1000 + 5; i++) {
    if (exist[i] == false) continue;
    int col = i;
    sort(del[i].begin(), del[i].end());
    for (auto bro : base[col]) {
      if (a[bro.first][bro.second] == col) continue;
      a[bro.first][bro.second] = col;
      par[bro.first][bro.second] = make_pair(bro.first, bro.second);
      int x = bro.first;
      int y = bro.second;
      for (int z = 0; z < 4; z++) {
        int ax = x + dx[z];
        int ay = y + dy[z];
        if (ax < 1 || ax > n || ay < 1 || ay > m) continue;
        if (a[ax][ay] == col) {
          u(x, y, ax, ay);
        }
      }
    }
    for (int j = (int)del[i].size() - 1; j >= 0; j--) {
      auto akt = del[i][j];
      int x = akt.second.first;
      int y = akt.second.second;
      par[x][y] = make_pair(0, 0);
    }
    for (int j = (int)del[i].size() - 1; j >= 0; j--) {
      auto akt = del[i][j];
      int cz = akt.first;
      int x = akt.second.first;
      int y = akt.second.second;
      if (par[x][y] == make_pair(x, y)) continue;
      par[x][y] = make_pair(x, y);
      a[x][y] = col;
      int cur = 1;
      for (int z = 0; z < 4; z++) {
        int ax = x + dx[z];
        int ay = y + dy[z];
        if (ax < 1 || ax > n || ay < 1 || ay > m) continue;
        if (a[ax][ay] == col) {
          cur -= u(x, y, ax, ay);
        }
      }
      cur *= -1;
      ans[cz] += cur;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = 1;
      par[i][j] = make_pair(0, 0);
    }
  }
  vector<pair<int, int> > bas;
  vector<pair<int, pair<int, int> > > de;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (ti[i][j].size() == 0)
        bas.push_back(make_pair(i, j));
      else {
        de.push_back(make_pair(*ti[i][j].begin(), make_pair(i, j)));
      }
    }
  }
  sort(de.begin(), de.end());
  ans[1]++;
  for (auto bro : bas) {
    int x = bro.first;
    int y = bro.second;
    par[x][y] = make_pair(x, y);
    a[x][y] = 0;
    for (int z = 0; z < 4; z++) {
      int ax = x + dx[z];
      int ay = y + dy[z];
      if (ax < 1 || ax > n || ay < 1 || ay > m) continue;
      if (a[ax][ay] == 0) {
        u(x, y, ax, ay);
      }
    }
  }
  for (int i = (int)de.size() - 1; i >= 0; i--) {
    auto akt = de[i];
    int cz = akt.first;
    int x = akt.second.first;
    int y = akt.second.second;
    if (par[x][y] == make_pair(x, y)) continue;
    par[x][y] = make_pair(x, y);
    a[x][y] = 0;
    int cur = 1;
    for (int z = 0; z < 4; z++) {
      int ax = x + dx[z];
      int ay = y + dy[z];
      if (ax < 1 || ax > n || ay < 1 || ay > m) continue;
      if (a[ax][ay] == 0) {
        cur -= u(x, y, ax, ay);
      }
    }
    cur *= -1;
    ans[cz] += cur;
  }
  for (int i = 1; i <= q; i++) {
    ans[i] += ans[i - 1];
    printf("%d\n", ans[i]);
  }
  return 0;
}
