#include <bits/stdc++.h>
using namespace std;
bitset<1000> state[1000];
struct query {
  int v, tp, x, y;
};
vector<query> g[100001];
int ans[100001];
int N, M, Q;
void dfs(int u) {
  int here = ans[u];
  for (const auto& q : g[u]) {
    int there = here;
    if (q.tp == 1) {
      bool b = state[q.x][q.y];
      if (!b) state[q.x][q.y] = true, there++;
      ans[q.v] = there;
      dfs(q.v);
      if (!b) state[q.x][q.y] = false;
    } else if (q.tp == 2) {
      bool b = state[q.x][q.y];
      if (b) state[q.x][q.y] = false, there--;
      ans[q.v] = there;
      dfs(q.v);
      if (b) state[q.x][q.y] = true;
    } else if (q.tp == 3) {
      int c = 0;
      for (int i = 0; i < M; i++)
        if (state[q.x][i]) c++;
      int there = here - c + M - c;
      state[q.x].flip();
      ans[q.v] = there;
      dfs(q.v);
      state[q.x].flip();
    } else {
      ans[q.v] = here;
      dfs(q.v);
    }
  }
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 1; i <= Q; i++) {
    int tp;
    scanf("%d", &tp);
    if (tp == 1 || tp == 2) {
      int x, y;
      scanf("%d%d", &x, &y);
      g[i - 1].push_back({i, tp, x - 1, y - 1});
    } else if (tp == 3) {
      int x;
      scanf("%d", &x);
      g[i - 1].push_back({i, tp, x - 1, -1});
    } else {
      int x;
      scanf("%d", &x);
      g[x].push_back({i, tp, -1, -1});
    }
  }
  dfs(0);
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
}
