#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, m, q;
vector<int> E[maxn];
int op[maxn], a[maxn], b[maxn], c[maxn];
int ans[maxn];
bitset<1001> Bit[1001];
bitset<1001> C;
void dfs(int x) {
  if (x == 0) {
    for (int i = 0; i < E[x].size(); i++) {
      ans[E[x][i]] = ans[x];
      dfs(E[x][i]);
    }
  }
  if (op[x] == 1) {
    int flag = 0;
    if (!Bit[a[x]][b[x]]) {
      flag = 1;
      ans[x]++;
      Bit[a[x]][b[x]] = 1;
    }
    for (int i = 0; i < E[x].size(); i++) {
      ans[E[x][i]] = ans[x];
      dfs(E[x][i]);
    }
    if (flag) Bit[a[x]][b[x]] = 0;
  }
  if (op[x] == 2) {
    int flag = 0;
    if (Bit[a[x]][b[x]]) {
      flag = 1;
      ans[x]--;
      Bit[a[x]][b[x]] = 0;
    }
    for (int i = 0; i < E[x].size(); i++) {
      ans[E[x][i]] = ans[x];
      dfs(E[x][i]);
    }
    if (flag) Bit[a[x]][b[x]] = 1;
  }
  if (op[x] == 3) {
    ans[x] = ans[x] - Bit[a[x]].count();
    Bit[a[x]] ^= C;
    ans[x] = ans[x] + Bit[a[x]].count();
    for (int i = 0; i < E[x].size(); i++) {
      ans[E[x][i]] = ans[x];
      dfs(E[x][i]);
    }
    Bit[a[x]] ^= C;
  }
  if (op[x] == 4) {
    for (int i = 0; i < E[x].size(); i++) {
      ans[E[x][i]] = ans[x];
      dfs(E[x][i]);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= m; i++) C[i] = 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &op[i]);
    if (op[i] == 1) scanf("%d%d", &a[i], &b[i]);
    if (op[i] == 2) scanf("%d%d", &a[i], &b[i]);
    if (op[i] == 3) scanf("%d", &a[i]);
    if (op[i] == 4)
      scanf("%d", &a[i]), E[a[i]].push_back(i);
    else
      E[i - 1].push_back(i);
  }
  dfs(0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
