#include <bits/stdc++.h>
using namespace std;
const int NM = 1e3 + 10, Q = 1e5 + 10, PERS = 4 * NM + 12 * Q;
int n, m, q;
int seg[PERS], L[PERS], R[PERS], node_cnt;
vector<bool> lin[PERS];
int build(int l, int r) {
  int idx = node_cnt++;
  if (l == r) {
    lin[idx] = vector<bool>(m + 1, 0);
  } else {
    int mid = (l + r) / 2;
    L[idx] = build(l, mid);
    R[idx] = build(mid + 1, r);
  }
  return idx;
}
int modify(int idx, int l, int r, int pos, int t, int j = 0) {
  int nidx = node_cnt++;
  if (l == r) {
    lin[nidx] = lin[idx];
    if (t == 1) {
      seg[nidx] = seg[idx];
      if (!lin[nidx][j]) lin[nidx][j] = 1, seg[nidx]++;
    } else if (t == 2) {
      seg[nidx] = seg[idx];
      if (lin[nidx][j]) lin[nidx][j] = 0, seg[nidx]--;
    } else if (t == 3) {
      for (int i = 1; i <= m; i++) {
        lin[nidx][i] = lin[nidx][i] ? 0 : 1;
        seg[nidx] += lin[nidx][i];
      }
    }
  } else {
    int mid = (l + r) / 2;
    if (pos <= mid) {
      L[nidx] = modify(L[idx], l, mid, pos, t, j);
      R[nidx] = R[idx];
    } else {
      L[nidx] = L[idx];
      R[nidx] = modify(R[idx], mid + 1, r, pos, t, j);
    }
    seg[nidx] = seg[L[nidx]] + seg[R[nidx]];
  }
  return nidx;
}
int root[Q];
int main() {
  scanf("%d %d %d", &n, &m, &q);
  root[0] = build(1, n);
  for (int k = 1; k <= q; k++) {
    int t;
    scanf("%d", &t);
    if (t == 1 || t == 2) {
      int i, j;
      scanf("%d %d", &i, &j);
      root[k] = modify(root[k - 1], 1, n, i, t, j);
    } else if (t == 3) {
      int i;
      scanf("%d", &i);
      root[k] = modify(root[k - 1], 1, n, i, 3);
    } else {
      int id;
      scanf("%d", &id);
      root[k] = root[id];
    }
    printf("%d\n", seg[root[k]]);
  }
  return 0;
}
