#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e3 + 1;
bitset<NMAX> shelf[NMAX];
int cnt[NMAX];
int n, m, q;
int books = 0;
struct Query {
  int type;
  int i, j;
  int res;
};
const int QMAX = 1e5 + 1;
Query queries[QMAX];
vector<int> adj[QMAX];
void calc(int u) {
  int i = queries[u].i, j = queries[u].j;
  if (queries[u].type == 4) {
    queries[u].res = books;
    for (int v : adj[u]) calc(v);
  } else if (queries[u].type == 1) {
    if (!shelf[i][j]) {
      shelf[i][j] = true;
      books++;
      cnt[i]++;
      queries[u].res = books;
      for (int v : adj[u]) calc(v);
      shelf[i][j] = false;
      books--;
      cnt[i]--;
    } else {
      queries[u].res = books;
      for (int v : adj[u]) calc(v);
    }
  } else if (queries[u].type == 2) {
    if (shelf[i][j]) {
      shelf[i][j] = false;
      books--;
      cnt[i]--;
      queries[u].res = books;
      for (int v : adj[u]) calc(v);
      shelf[i][j] = true;
      books++;
      cnt[i]++;
    } else {
      queries[u].res = books;
      for (int v : adj[u]) calc(v);
    }
  } else if (queries[u].type == 3) {
    books += m - 2 * cnt[i];
    cnt[i] = m - cnt[i];
    shelf[i].flip();
    queries[u].res = books;
    for (int v : adj[u]) calc(v);
    books += m - 2 * cnt[i];
    cnt[i] = m - cnt[i];
    shelf[i].flip();
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  queries[0].type = 4;
  for (int i = 1; i <= q; i++) {
    int type, a, b;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d", &a, &b);
      queries[i] = {type, a, b, 0};
      adj[i - 1].push_back(i);
    } else if (type == 2) {
      scanf("%d%d", &a, &b);
      queries[i] = {type, a, b, 0};
      adj[i - 1].push_back(i);
    } else if (type == 3) {
      scanf("%d", &a);
      queries[i] = {type, a, 0, 0};
      adj[i - 1].push_back(i);
    } else if (type == 4) {
      int p;
      scanf("%d", &p);
      queries[i] = {type, 0, 0, 0};
      adj[p].push_back(i);
    }
  }
  calc(0);
  for (int i = 1; i <= q; i++) {
    printf("%d\n", queries[i].res);
  }
}
