#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tos(T a) {
  stringstream ss;
  string ret;
  ss << a;
  ss >> ret;
  return ret;
}
void read(int &_a) { int temp = scanf("%d", &_a); }
void read(int &_a, int &_b) { int temp = scanf("%d %d", &_a, &_b); }
void read(int &_a, int &_b, int &_c) {
  int temp = scanf("%d %d %d", &_a, &_b, &_c);
}
const int DIM = 302;
const int COL = 2e6 + 7;
const int MXQ = 2e6 + 7;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int R, C;
int RN[DIM * DIM], P[DIM * DIM], OC[DIM * DIM], ANS[MXQ], NW[DIM][DIM];
vector<pair<int, int> > H[COL], RH[COL];
int getp(int u) {
  if (u != P[u])
    return P[u] = getp(P[u]);
  else
    return u;
}
int unite(int u, int v) {
  u = getp(u);
  v = getp(v);
  if (u == v) return 0;
  if (RN[u] < RN[v]) swap(u, v);
  P[v] = u;
  RN[u] += RN[v];
  return 1;
}
inline void process(const vector<pair<int, int> > &V, int coeff, int c) {
  int l = V.size();
  for (int(i) = (0); (i) < (l); (i)++) {
    int v = V[i].first;
    int x = v / C;
    int y = v % C;
    RN[v] = OC[v] = 0;
    P[v] = v;
    for (int(k) = (0); (k) < (4); (k)++) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      if (nx >= 0 && nx < R && ny >= 0 && ny < C) {
        int nv = nx * C + ny;
        RN[nv] = OC[nv] = 0;
        P[nv] = nv;
      }
    }
  }
  for (int(i) = (0); (i) < (l); (i)++) {
    int v = V[i].first;
    int t = V[i].second;
    OC[v] = 1;
    int comp = 1;
    int x = v / C;
    int y = v % C;
    for (int(k) = (0); (k) < (4); (k)++) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      if (nx >= 0 && nx < R && ny >= 0 && ny < C) {
        int nv = nx * C + ny;
        if (OC[nv] == 1) comp -= unite(v, nv);
      }
    }
    ANS[t] += comp * coeff;
  }
}
int main() {
  while (cin >> R >> C) {
    for (int(x) = (0); (x) < (COL); (x)++) H[x].clear();
    for (int(x) = (0); (x) < (COL); (x)++) RH[x].clear();
    memset(ANS, 0, sizeof ANS);
    ;
    memset(NW, 0, sizeof NW);
    ;
    int q, x, y, c;
    read(q);
    int mxc = 0;
    for (int(tm) = (1); (tm) < (q + 1); (tm)++) {
      read(x, y, c);
      x--;
      y--;
      if (NW[x][y] == c) continue;
      mxc = c + 1;
      H[c].push_back(make_pair(x * C + y, tm));
      RH[NW[x][y]].push_back(make_pair(x * C + y, tm));
      NW[x][y] = c;
    }
    for (int(x) = (0); (x) < (R); (x)++)
      for (int(y) = (0); (y) < (C); (y)++) {
        RH[NW[x][y]].push_back(make_pair(x * C + y, q + 1));
      }
    for (int(x) = (0); (x) < (mxc); (x)++) {
      if (RH[x].size() == 0) continue;
      reverse(RH[x].begin(), RH[x].end());
    }
    for (int(x) = (0); (x) < (mxc); (x)++)
      if (H[x].size() > 0) process(H[x], +1, x);
    for (int(x) = (0); (x) < (mxc); (x)++)
      if (RH[x].size() > 0) process(RH[x], -1, x);
    int ans = 1;
    for (int(tm) = (1); (tm) < (q + 1); (tm)++) {
      ans += ANS[tm];
      printf("%d\n", ans);
    }
  }
  return 0;
}
