#include <bits/stdc++.h>
struct DSU {
  std::vector<int> parent, sizes;
  DSU(int size) : parent(size + 1), sizes(size + 1) {
    for (int i = 0; i <= size; i++) {
      parent[i] = i;
      sizes[i] = 1;
    }
  }
  int findParent(int x) {
    if (x != parent[x]) {
      parent[x] = findParent(parent[x]);
    }
    return parent[x];
  }
  void merge(int a, int b) {
    int pa = findParent(a);
    int pb = findParent(b);
    if (pa == pb) return;
    if (sizes[pa] < sizes[pb]) std::swap(pa, pb);
    parent[pb] = parent[pa];
    sizes[pa] += sizes[pb];
  }
  int getSize(int x) { return sizes[findParent(x)]; }
};
struct Point {
  int x, y, time;
};
struct P {
  int x, y;
};
int w, h, q;
std::vector<int> diff;
std::vector<std::vector<Point>> cAdd, cRem;
std::vector<std::vector<int>> mat;
std::vector<std::vector<P>> initAdjX, initAdjY;
std::vector<std::vector<P>> initMat;
int countComp(int x, int y, DSU &dsu) {
  std::vector<P> p;
  if (x > 0) p.push_back({x - 1, y});
  if (x < w - 1) p.push_back({x + 1, y});
  if (y > 0) p.push_back({x, y - 1});
  if (y < h - 1) p.push_back({x, y + 1});
  for (int i1 = 0; i1 < p.size(); i1++) {
    auto &p1 = p[i1];
    for (int i2 = i1 + 1; i2 < p.size(); i2++) {
      auto &p2 = p[i2];
      if (dsu.findParent(p1.x + p1.y * w) == dsu.findParent(p2.x + p2.y * w)) {
        std::swap(p2, p.back());
        p.pop_back();
        i2--;
      }
    }
  }
  return p.size();
}
int main() {
  scanf("%d %d %d", &w, &h, &q);
  mat.resize(h, std::vector<int>(w));
  diff.resize(q + 1);
  for (int i = 0; i < q; i++) {
    int x, y, c;
    scanf("%d %d %d", &x, &y, &c);
    x--;
    y--;
    while (cAdd.size() <= c) {
      cAdd.push_back({});
      cRem.push_back({});
    }
    int pc = mat[y][x];
    if (c == pc) continue;
    cAdd[c].push_back({x, y, i});
    cRem[pc].push_back({x, y, i});
    mat[y][x] = c;
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      mat[y][x] = 0;
    }
  }
  for (int i = 0; i < cAdd.size(); i++) {
    DSU dsu(w * h);
    for (auto &p : cAdd[i]) {
      mat[p.y][p.x] = i;
      int pc = countComp(p.x, p.y, dsu);
      int adj = 0;
      if (p.x > 0 && mat[p.y][p.x - 1] == i) {
        dsu.merge(p.x + p.y * w, p.x - 1 + p.y * w);
        adj++;
      }
      if (p.x < w - 1 && mat[p.y][p.x + 1] == i) {
        dsu.merge(p.x + p.y * w, p.x + 1 + p.y * w);
        adj++;
      }
      if (p.y > 0 && mat[p.y - 1][p.x] == i) {
        dsu.merge(p.x + p.y * w, p.x + (p.y - 1) * w);
        adj++;
      }
      if (p.y < h - 1 && mat[p.y + 1][p.x] == i) {
        dsu.merge(p.x + p.y * w, p.x + (p.y + 1) * w);
        adj++;
      }
      if (adj == 0) {
        diff[p.time]++;
      } else {
        int cc = countComp(p.x, p.y, dsu);
        diff[p.time] += cc - pc;
      }
    }
  }
  initMat.resize(cAdd.size());
  initAdjX.resize(cAdd.size());
  initAdjY.resize(cAdd.size());
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      initMat[mat[y][x]].push_back({x, y});
    }
  }
  for (int y = 0; y < h - 1; y++) {
    for (int x = 0; x < w; x++) {
      int c = mat[y][x];
      if (mat[y + 1][x] == c) initAdjY[c].push_back({x, y});
    }
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w - 1; x++) {
      int c = mat[y][x];
      if (mat[y][x + 1] == c) initAdjX[c].push_back({x, y});
    }
  }
  for (int i = 0; i < cRem.size(); i++) {
    DSU dsu(w * h);
    for (auto &p : initMat[i]) {
      mat[p.y][p.x] = i;
    }
    for (auto &p : initAdjX[i]) {
      dsu.merge(p.x + p.y * w, p.x + 1 + p.y * w);
    }
    for (auto &p : initAdjY[i]) {
      dsu.merge(p.x + p.y * w, p.x + (p.y + 1) * w);
    }
    for (int i2 = cRem[i].size() - 1; i2 >= 0; i2--) {
      auto &p = cRem[i][i2];
      mat[p.y][p.x] = i;
      int pc = countComp(p.x, p.y, dsu);
      int adj = 0;
      if (p.x > 0 && mat[p.y][p.x - 1] == i) {
        dsu.merge(p.x + p.y * w, p.x - 1 + p.y * w);
        adj++;
      }
      if (p.x < w - 1 && mat[p.y][p.x + 1] == i) {
        dsu.merge(p.x + p.y * w, p.x + 1 + p.y * w);
        adj++;
      }
      if (p.y > 0 && mat[p.y - 1][p.x] == i) {
        dsu.merge(p.x + p.y * w, p.x + (p.y - 1) * w);
        adj++;
      }
      if (p.y < h - 1 && mat[p.y + 1][p.x] == i) {
        dsu.merge(p.x + p.y * w, p.x + (p.y + 1) * w);
        adj++;
      }
      if (adj == 0) {
        diff[p.time]--;
      } else {
        int cc = countComp(p.x, p.y, dsu);
        diff[p.time] -= cc - pc;
      }
    }
  }
  int ans = 1;
  for (int i = 0; i < q; i++) {
    ans += diff[i];
    printf("%d\n", ans);
  }
  return 0;
}
