#include <bits/stdc++.h>
using namespace std;
vector<int> id[100010];
vector<bool> ps[200010];
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    id[0].push_back(i);
    ps[i] = vector<bool>(m + 1);
  }
  vector<int> anw(q + 1);
  int idd = n;
  for (int i = 1; i <= q; i++) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int xi, xj;
      scanf("%d%d", &xi, &xj);
      xi--;
      xj--;
      id[i] = id[i - 1];
      ps[idd] = ps[id[i][xi]];
      id[i][xi] = idd;
      int ma = anw[i - 1];
      if (ps[idd][m] == ps[idd][xj]) {
        ps[idd][xj] = ps[idd][xj] ^ 1;
        ma++;
      }
      anw[i] = ma;
      idd++;
      printf("%d\n", ma);
    }
    if (op == 2) {
      int xi, xj;
      scanf("%d%d", &xi, &xj);
      xi--;
      xj--;
      id[i] = id[i - 1];
      ps[idd] = ps[id[i][xi]];
      id[i][xi] = idd;
      int ma = anw[i - 1];
      if (ps[idd][m] ^ ps[idd][xj]) {
        ps[idd][xj] = ps[idd][xj] ^ 1;
        ma--;
      }
      anw[i] = ma;
      idd++;
      printf("%d\n", ma);
    }
    if (op == 3) {
      int xi;
      scanf("%d", &xi);
      xi--;
      id[i] = id[i - 1];
      ps[idd] = ps[id[i][xi]];
      id[i][xi] = idd;
      int ma = anw[i - 1];
      for (int j = 0; j < m; j++) {
        if (ps[idd][m] == ps[idd][j])
          ma++;
        else
          ma--;
      }
      ps[idd][m] = ps[idd][m] ^ 1;
      anw[i] = ma;
      idd++;
      printf("%d\n", ma);
    }
    if (op == 4) {
      int xk;
      scanf("%d", &xk);
      id[i] = id[xk];
      anw[i] = anw[xk];
      printf("%d\n", anw[i]);
    }
  }
}
