#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int maxn = 1000 + 77;
const int maxq = 1e5 + 7;
int n, m, t, T;
int ans[maxq];
struct node {
  int type, v1, v2;
} Q[maxq];
vector<int> G[maxq];
int a, b, q, k;
void update(int rt, int type, int v1 = 0, int v2 = 0) {
  Q[rt].type = type;
  Q[rt].v1 = v1;
  Q[rt].v2 = v2;
  if (type == 4)
    G[v1].push_back(rt);
  else
    G[rt - 1].push_back(rt);
}
bitset<maxn> bit[maxn];
int vis[maxn];
void dfs(int i, int res) {
  ans[i] = res;
  int w = G[i].size();
  for (int j = 0; j < w; j++) {
    int next = G[i][j];
    if (Q[next].type == 1) {
      int a = Q[next].v1 - 1, b = Q[next].v2 - 1;
      if (bit[a][b] == 0) {
        bit[a][b] = 1;
        dfs(next, res + 1);
        bit[a][b] = 0;
      } else
        dfs(next, res);
    } else if (Q[next].type == 2) {
      int a = Q[next].v1 - 1, b = Q[next].v2 - 1;
      if (bit[a][b] == 1) {
        bit[a][b] = 0;
        dfs(next, res - 1);
        bit[a][b] = 1;
      } else
        dfs(next, res);
    } else if (Q[next].type == 3) {
      int ads = maxn - m;
      int a = Q[next].v1 - 1;
      int tmp = bit[a].count();
      if (vis[a]) tmp -= ads;
      bit[a].flip();
      vis[a] = 1 - vis[a];
      tmp -= bit[a].count();
      if (vis[a]) tmp += ads;
      dfs(next, res - tmp);
      bit[a].flip();
      vis[a] = 1 - vis[a];
    } else
      dfs(next, res);
  }
}
int main() {
  update(0, 0);
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &t);
    if (t == 1 || t == 2) {
      scanf("%d%d", &a, &b);
      update(i, t, a, b);
    } else if (t == 3) {
      scanf("%d", &a);
      update(i, t, a);
    } else if (t == 4) {
      scanf("%d", &a);
      update(i, t, a);
    }
  }
  (memset(vis, 0, sizeof(vis)));
  dfs(0, 0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
