#include <bits/stdc++.h>
using namespace std;
const int MAX1 = 1e3 + 1, MAX2 = 1e5 + 1;
int n, m, q;
long long ans[MAX2];
bool inv[MAX1];
set<int> t[MAX1];
vector<int> g[MAX2];
pair<int, pair<int, int>> h[MAX2];
void dfs(int x) {
  int type = h[x].first, y = h[x].second.first, z = h[x].second.second;
  bool done = 0;
  if (type == 1) {
    if ((t[y].find(z) != t[y].end()) == inv[y]) {
      done = 1;
      ++ans[x];
      if (inv[y])
        t[y].erase(z);
      else
        t[y].insert(z);
    }
  } else if (type == 2) {
    if ((t[y].find(z) != t[y].end()) != inv[y]) {
      done = 1;
      --ans[x];
      if (inv[y])
        t[y].insert(z);
      else
        t[y].erase(z);
    }
  } else if (type == 3) {
    done = 1;
    inv[y] = !inv[y];
    ans[x] += inv[y] ? m - 2 * (int)t[y].size() : -(m - 2 * (int)t[y].size());
  }
  for (int a : g[x]) {
    ans[a] = ans[x];
    dfs(a);
  }
  if (type == 1) {
    if (done) {
      if (inv[y])
        t[y].insert(z);
      else
        t[y].erase(z);
    }
  } else if (type == 2) {
    if (done) {
      if (inv[y])
        t[y].erase(z);
      else
        t[y].insert(z);
    }
  } else if (type == 3) {
    inv[y] = !inv[y];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    int x, y, z;
    cin >> x >> y;
    if (x == 4)
      g[y].push_back(i);
    else if (x == 3) {
      g[i - 1].push_back(i);
      h[i] = {x, {y, 0}};
    } else {
      cin >> z;
      g[i - 1].push_back(i);
      h[i] = {x, {y, z}};
    }
  }
  dfs(0);
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
