#include <bits/stdc++.h>
using namespace std;
int n, m, q, type[100100], fir[100100], sec[100100], ans[100100];
bool happen[100100];
vector<int> G[100100];
bitset<1050> book[1005], all;
void dfs(int o, int res) {
  if (type[o] == 1) {
    if (!book[fir[o]][sec[o]]) {
      book[fir[o]][sec[o]] = 1;
      happen[o] = true;
      res++;
    }
  }
  if (type[o] == 2) {
    if (book[fir[o]][sec[o]]) {
      book[fir[o]][sec[o]] = 0;
      happen[o] = true;
      res--;
    }
  }
  if (type[o] == 3) {
    res -= book[fir[o]].count();
    book[fir[o]] ^= all;
    res += book[fir[o]].count();
    happen[o] = true;
  }
  ans[o] = res;
  for (auto &i : G[o]) {
    dfs(i, res);
  }
  if (type[o] == 4) {
    return;
  }
  if (type[o] == 1) {
    if (happen[o]) {
      book[fir[o]][sec[o]] = 0;
    }
  }
  if (type[o] == 2) {
    if (happen[o]) {
      book[fir[o]][sec[o]] = 1;
    }
  }
  if (type[o] == 3) {
    book[fir[o]] ^= all;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; ++i) {
    all[i] = 1;
  }
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &type[i], &fir[i]);
    if (type[i] == 1 || type[i] == 2) {
      scanf("%d", &sec[i]);
      sec[i]--;
    }
    if (type[i] == 4) {
      G[fir[i]].push_back(i);
    } else {
      G[i - 1].push_back(i);
    }
  }
  dfs(0, 0);
  for (int i = 1; i <= q; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
