#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int (*itoi)(int);
typedef int (*iitoi)(int, int);
typedef int (*iiitoi)(int, int, int);
typedef ll (*ltol)(ll);
typedef ll (*lltol)(ll, ll);
typedef ll (*llltol)(ll, ll, ll);
const long double PI = acos(0) * 2;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
int X4[] = {-1, 0, 1, 0}, Y4[] = {0, -1, 0, 1};
int X8[] = {-1, -1, -1, 0, 1, 1, 1, 0}, Y8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
template <typename T>
inline bool uax(T& a, T b) {
  return a < b ? (a = b, 1) : 0;
}
template <typename T>
inline bool uin(T& a, T b) {
  return a > b ? (a = b, 1) : 0;
}
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
  return is >> p.first >> p.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << '(' << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i];
    if (i + 1 < (int)v.size()) os << ' ';
  }
  return os;
}
class union_find {
 public:
  int max_node;
  vector<int> parents;
  union_find(int max_node) {
    this->max_node = max_node;
    parents.assign(max_node + 1, 0);
    for (int i = 0; i <= max_node; i++) parents[i] = i;
  }
  void init() {
    for (int i = 0; i <= max_node; i++) parents[i] = i;
  }
  int find(int a) {
    return parents[a] == a ? a : parents[a] = find(parents[a]);
  }
  bool unio(int a, int b) {
    parents[a = find(a)] = b = find(b);
    return a != b;
  }
  void print() {
    for (int i = 1; i <= max_node; i++) cout << find(i) << ' ';
    cout << endl;
  }
};
const int MAX_N = 302, MAX_Q = 2e6 + 10;
int N, M, Q;
vector<tuple<int, int, int> > Add[MAX_Q], Del[MAX_Q];
int Dlt[MAX_Q];
int A[MAX_N][MAX_N];
union_find Uf(MAX_N* MAX_N);
inline int id(int a, int b) { return a * MAX_N + b; }
void calc(int cl, vector<tuple<int, int, int> >& v, int prod) {
  for (auto [a, b, idx] : v) {
    int cur = 1;
    for (int k = 0; k < 4; k++) {
      int na = a + "1012"[k] - '1';
      int nb = b + "0121"[k] - '1';
      if (na >= 1 && na <= N && nb >= 1 && nb <= M && A[na][nb] == cl) {
        cur -= Uf.unio(id(a, b), id(na, nb));
      }
    }
    Dlt[idx] += cur * prod;
    A[a][b] = cl;
  }
  for (auto [a, b, idx] : v) {
    (void)idx;
    Uf.parents[id(a, b)] = id(a, b);
    A[a][b] = -1;
  }
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  int mxc = 0;
  for (int i = 1; i <= Q; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    Add[c].emplace_back(a, b, i);
    Del[A[a][b]].emplace_back(a, b, i);
    A[a][b] = c;
    uax(mxc, c);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      Del[A[i][j]].emplace_back(i, j, Q + 1);
      A[i][j] = -1;
    }
  }
  for (int c = 0; c <= mxc; c++) reverse((Del[c]).begin(), (Del[c]).end());
  for (int c = 0; c <= mxc; c++) calc(c, Add[c], 1);
  for (int c = 0; c <= mxc; c++) calc(c, Del[c], -1);
  int ans = 1;
  for (int q = 1; q <= Q; q++) {
    ans += Dlt[q];
    printf("%d\n", ans);
  }
  return 0;
}
