#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1005, Q = 1e5 + 5;
int n, m, a[N][N], q, ans[Q], type[Q], r[Q], c[Q];
bool vis[Q];
vector<int> g[Q];
int cur = 0;
void dfs(int u) {
  if (u == q + 1) return;
  if (vis[u]) return;
  vis[u] = 1;
  bool rev = 0;
  if (type[u] == 1) {
    if (a[r[u]][c[u]] == 0) cur++, a[r[u]][c[u]] = 1, rev = 1;
  } else if (type[u] == 2) {
    if (a[r[u]][c[u]] == 1) cur--, a[r[u]][c[u]] = 0, rev = 1;
  } else if (type[u] == 3) {
    for (int j = 1; j <= m; j++) {
      if (a[r[u]][j] == 0)
        cur++;
      else
        cur--;
      a[r[u]][j] ^= 1;
    }
  } else if (type[u] == 4)
    return;
  ans[u] = cur;
  for (auto v : g[u]) dfs(v + 1);
  if (rev) {
    if (type[u] == 1) {
      a[r[u]][c[u]] ^= 1, cur--;
    } else if (type[u] == 2) {
      a[r[u]][c[u]] ^= 1, cur++;
    }
  }
  if (type[u] == 3) {
    for (int j = 1; j <= m; j++) {
      if (a[r[u]][j] == 1)
        cur--;
      else
        cur++;
      a[r[u]][j] ^= 1;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> q;
  type[0] = 0;
  for (int i = 1; i <= q; i++) {
    cin >> type[i] >> r[i];
    if (type[i] < 3) cin >> c[i];
  }
  for (int i = 1; i <= q; i++)
    if (type[i] == 4 && type[r[i]] == 4) r[i] = r[r[i]];
  for (int i = 0; i <= q; i++) {
    g[i].push_back(i);
    if (type[i] == 4) g[r[i]].push_back(i);
  }
  for (int i = 0; i <= q; i++) dfs(i);
  for (int i = 1; i <= q; i++) {
    if (type[i] == 4)
      cout << ans[r[i]] << "\n";
    else
      cout << ans[i] << "\n";
  }
  return 0;
}
