#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  int f = 0, c = getchar();
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  if (f) x = -x;
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args) {
  read(x);
  read(args...);
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
template <typename T>
inline bool chkmin(T& x, const T& y) {
  return y < x ? (x = y, true) : false;
}
template <typename T>
inline bool chkmax(T& x, const T& y) {
  return x < y ? (x = y, true) : false;
}
const int maxn = (int)1e5 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 998244353ll;
int n, m, q, ans[maxn], res, op[maxn], x[maxn], y[maxn];
bool g[1001][1001];
vector<int> es[maxn];
void dfs(int u) {
  bool valid = 0;
  if (op[u] == 1) {
    if (!g[x[u]][y[u]]) {
      valid = 1, g[x[u]][y[u]] = 1, res++;
    }
  }
  if (op[u] == 2) {
    if (g[x[u]][y[u]]) {
      valid = 1, g[x[u]][y[u]] = 0, res--;
    }
  }
  if (op[u] == 3) {
    for (int i = (1); i < (m + 1); i++) {
      if (g[x[u]][i]) {
        g[x[u]][i] = 0, res--;
      } else {
        g[x[u]][i] = 1, res++;
      }
    }
  }
  ans[u] = res;
  for (int i = (0); i < ((int)es[u].size()); i++) {
    dfs(es[u][i]);
  }
  if (op[u] == 1 && valid) {
    if (g[x[u]][y[u]]) {
      g[x[u]][y[u]] = 0, res--;
    }
  }
  if (op[u] == 2 && valid) {
    if (!g[x[u]][y[u]]) {
      g[x[u]][y[u]] = 1, res++;
    }
  }
  if (op[u] == 3) {
    for (int i = (1); i < (m + 1); i++) {
      if (!g[x[u]][i]) {
        g[x[u]][i] = 1, res++;
      } else {
        g[x[u]][i] = 0, res--;
      }
    }
  }
}
int main() {
  read(n, m, q);
  for (int i = (1); i < (q + 1); i++) {
    read(op[i], x[i]);
    if (op[i] <= 2)
      read(y[i]), es[i - 1].push_back(i);
    else if (op[i] == 3)
      es[i - 1].push_back(i);
    else
      es[x[i]].push_back(i);
  }
  dfs(0);
  for (int i = (1); i < (q + 1); i++) {
    writeln(ans[i]);
  }
}
