#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int Q = (int)1e5 + 5;
const int N = (int)1e3 + 5;
int a[N][N], t[Q], x[Q], y[Q], cur, cnt[N], n, m, q, ans[Q];
bool change[Q], inv[N];
vector<int> v[Q];
void dfs(int p) {
  if (t[p] == 3) change[p] = true;
  if (t[p] == 1) {
    if (inv[x[p]] && a[x[p]][y[p]] == 1) change[p] = true;
    if (!inv[x[p]] && a[x[p]][y[p]] == 0) change[p] = true;
  }
  if (t[p] == 2) {
    if (!inv[x[p]] && a[x[p]][y[p]] == 1) change[p] = true;
    if (inv[x[p]] && a[x[p]][y[p]] == 0) change[p] = true;
  }
  if (t[p] == 1 && change[p]) {
    cur++;
    cnt[x[p]]++;
  }
  if (t[p] == 2 && change[p]) {
    cur--;
    cnt[x[p]]--;
  }
  if (t[p] < 3 && change[p])
    if (a[x[p]][y[p]] == 0)
      a[x[p]][y[p]] = 1;
    else
      a[x[p]][y[p]] = 0;
  if (t[p] == 3) {
    cur -= cnt[x[p]];
    cur += m - cnt[x[p]];
    cnt[x[p]] = m - cnt[x[p]];
    if (inv[x[p]])
      inv[x[p]] = false;
    else
      inv[x[p]] = true;
  }
  ans[p] = cur;
  for (int i = 0; i < v[p].size(); i++) dfs(v[p][i]);
  if (change[p]) {
    if (t[p] == 1) {
      cur--;
      cnt[x[p]]--;
    }
    if (t[p] == 2) {
      cur++;
      cnt[x[p]]++;
    }
    if (t[p] == 3) {
      cur -= cnt[x[p]];
      cur += m - cnt[x[p]];
      cnt[x[p]] = m - cnt[x[p]];
      if (inv[x[p]])
        inv[x[p]] = false;
      else
        inv[x[p]] = true;
    }
    if (t[p] < 3)
      if (a[x[p]][y[p]] == 1)
        a[x[p]][y[p]] = 0;
      else
        a[x[p]][y[p]] = 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    cin >> t[i] >> x[i];
    if (t[i] != 4) x[i]--;
    if (t[i] < 3) {
      cin >> y[i];
      y[i]--;
    }
    if (t[i] == 4)
      v[x[i]].push_back(i);
    else
      v[i - 1].push_back(i);
  }
  dfs(0);
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
