#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 1005;
int op[N], x[N], y[N], an[N], ans;
int head[N], lnk[N], nxt[N], tot;
int sum[M], n, m, q;
bool a[M][M], rev[M], suc[N];
void link(int x, int y) {
  lnk[++tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
bool modify(int x, int y, int d) {
  if ((a[x][y] ^ rev[x]) != d) {
    a[x][y] = d ^ rev[x];
    if (a[x][y] ^ rev[x])
      sum[x]++;
    else
      sum[x]--;
    return 1;
  }
  return 0;
}
void dfs(int o) {
  if (op[o] == 1) suc[o] = modify(x[o], y[o], 1), ans += suc[o];
  if (op[o] == 2) suc[o] = modify(x[o], y[o], 0), ans -= suc[o];
  if (op[o] == 3)
    suc[o] = 1, rev[x[o]] ^= 1, ans += m - sum[x[o]] - sum[x[o]],
    sum[x[o]] = m - sum[x[o]];
  an[o] = ans;
  for (int i = head[o]; i; i = nxt[i]) dfs(lnk[i]);
  if (suc[o]) {
    if (op[o] == 1) modify(x[o], y[o], 0), ans--;
    if (op[o] == 2) modify(x[o], y[o], 1), ans++;
    if (op[o] == 3)
      rev[x[o]] ^= 1, sum[x[o]] = m - sum[x[o]],
                      ans -= m - sum[x[o]] - sum[x[o]];
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &op[i]);
    if (op[i] <= 2)
      scanf("%d%d", &x[i], &y[i]);
    else
      scanf("%d", &x[i]);
    if (op[i] == 4)
      link(x[i], i);
    else
      link(i - 1, i);
  }
  dfs(0);
  for (int i = 1; i <= q; i++) printf("%d\n", an[i]);
  return 0;
}
