#include <bits/stdc++.h>
using namespace std;
struct arr {
  int to, ne;
} e[100001];
int n, m, k, cnt, x[100001], y[100001], opt[100001], ans[100001], head[100001],
    f[1001][1001];
inline int read() {
  int x = 0, c = getchar();
  while (c < 48) c = getchar();
  while (c > 47) x = (x << 1) + (x << 3) + c - 48, c = getchar();
  return x;
}
inline void add(int x, int y) {
  e[++cnt].to = y;
  e[cnt].ne = head[x];
  head[x] = cnt;
}
void dfs(int num, int sum) {
  ans[num] = sum;
  for (int i = head[num]; i; i = e[i].ne) {
    if (opt[e[i].to] == 1) {
      if (!f[x[e[i].to]][y[e[i].to]]) {
        f[x[e[i].to]][y[e[i].to]] = 1;
        dfs(e[i].to, sum + 1);
        f[x[e[i].to]][y[e[i].to]] = 0;
      } else
        dfs(e[i].to, sum);
    } else if (opt[e[i].to] == 2) {
      if (f[x[e[i].to]][y[e[i].to]]) {
        f[x[e[i].to]][y[e[i].to]] = 0;
        dfs(e[i].to, sum - 1);
        f[x[e[i].to]][y[e[i].to]] = 1;
      } else
        dfs(e[i].to, sum);
    } else if (opt[e[i].to] == 3) {
      int p = 0, t = x[e[i].to];
      for (int j = 1; j <= m; j++) {
        if (f[t][j])
          p--;
        else
          p++;
        f[t][j] ^= 1;
      }
      dfs(e[i].to, sum + p);
      for (int j = 1; j <= m; j++) f[t][j] ^= 1;
    } else
      dfs(e[i].to, sum);
  }
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
int main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= k; i++) {
    opt[i] = read();
    if (opt[i] < 3) x[i] = read(), y[i] = read(), add(i - 1, i);
    if (opt[i] == 3) x[i] = read(), add(i - 1, i);
    if (opt[i] > 3) x[i] = read(), add(x[i], i);
  }
  dfs(0, 0);
  for (int i = 1; i <= k; i++) print(ans[i]), putchar('\n');
}
