#include <bits/stdc++.h>
using namespace std;
vector<int> id[100010];
vector<bool> ps[200010];
struct query {
  int t;
  int id1, id2;
};
bool ndd[100010];
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<query> queries;
  for (int i = 0; i < q; i++) {
    query tt;
    scanf("%d%d", &tt.t, &tt.id1);
    if (tt.t < 3) scanf("%d", &tt.id2);
    if (tt.t == 4) ndd[tt.id1] = 1;
    queries.push_back(tt);
  }
  vector<int> anw(q + 1);
  int idd = n;
  for (int i = 1; i <= q; i++) {
    int op = queries[i - 1].t;
    if (op == 1) {
      int xi = queries[i - 1].id1;
      int xj = queries[i - 1].id2;
      xi--;
      xj--;
      id[i] = id[i - 1];
      if (!ndd[i - 1]) id[i - 1].clear();
      ps[idd] = ps[id[i][xi]];
      id[i][xi] = idd;
      anw[i] = anw[i - 1];
      if (ps[idd][m] == ps[idd][xj]) {
        ps[idd][xj] = ps[idd][xj] ^ 1;
        anw[i]++;
      }
      idd++;
      printf("%d\n", anw[i]);
    }
    if (op == 2) {
      int xi = queries[i - 1].id1;
      int xj = queries[i - 1].id2;
      xi--;
      xj--;
      id[i] = id[i - 1];
      if (!ndd[i - 1]) id[i - 1].clear();
      ps[idd] = ps[id[i][xi]];
      id[i][xi] = idd;
      anw[i] = anw[i - 1];
      if (ps[idd][m] ^ ps[idd][xj]) {
        ps[idd][xj] = ps[idd][xj] ^ 1;
        anw[i]--;
      }
      idd++;
      printf("%d\n", anw[i]);
    }
    if (op == 3) {
      int xi = queries[i - 1].id1;
      xi--;
      id[i] = id[i - 1];
      if (!ndd[i - 1]) id[i - 1].clear();
      ps[idd] = ps[id[i][xi]];
      id[i][xi] = idd;
      anw[i] = anw[i - 1];
      for (int j = 0; j < m; j++) {
        if (ps[idd][m] == ps[idd][j])
          anw[i]++;
        else
          anw[i]--;
      }
      ps[idd][m] = ps[idd][m] ^ 1;
      idd++;
      printf("%d\n", anw[i]);
    }
    if (op == 4) {
      int xk = queries[i - 1].id1;
      id[i] = id[xk];
      anw[i] = anw[xk];
      printf("%d\n", anw[i]);
    }
  }
}
