#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct Node {
  int l, r, val;
};
int nodecnt = 0;
Node it[N * 24];
int root[N];
bitset<1024> a[N];
int ans[N];
int build(int lo, int hi) {
  int u = nodecnt++;
  it[u].val = 0;
  if (lo < hi) {
    int m = (lo + hi) >> 1;
    it[u].l = build(lo, m);
    it[u].r = build(m + 1, hi);
  }
  return u;
}
int update(int u, int lo, int hi, int id, int val) {
  int v = nodecnt++;
  it[v].l = it[u].l;
  it[v].r = it[u].r;
  if (lo == hi) {
    assert(lo == hi);
    it[v].val = val;
    return v;
  }
  int m = (lo + hi) >> 1;
  if (id <= m) {
    int tmp = update(it[u].l, lo, m, id, val);
    it[v].l = tmp;
  } else {
    int tmp = update(it[u].r, m + 1, hi, id, val);
    it[v].r = tmp;
  }
  return v;
}
int query(int u, int lo, int hi, int id) {
  if (lo == hi) {
    assert(lo == hi);
    return it[u].val;
  }
  int m = (lo + hi) >> 1;
  if (id <= m)
    return query(it[u].l, lo, m, id);
  else
    return query(it[u].r, m + 1, hi, id);
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  root[0] = build(1, n);
  ans[0] = 0;
  bitset<1024> all;
  for (int i = 0; i < m; i++) all.set(i);
  for (int i = 1; i <= q; i++) {
    int code, u, v;
    scanf("%d%d", &code, &u);
    if (code <= 2) scanf("%d", &v);
    if (code == 4) {
      root[i] = root[u];
      ans[i] = ans[u];
    } else {
      int tmp = query(root[i - 1], 1, n, u);
      ans[i] = ans[i - 1] - a[tmp].count();
      if (code != 3) {
        a[i] = a[tmp];
        if (code == 1)
          a[i].set(v - 1);
        else
          a[i].reset(v - 1);
      } else
        a[i] = a[tmp] ^ all;
      ans[i] += a[i].count();
      root[i] = update(root[i - 1], 1, n, u, i);
    }
    printf("%d\n", ans[i]);
  }
  return 0;
}
