#include <bits/stdc++.h>
using namespace std;
int n, m, q, cnt = 0;
vector<int> g[100111];
int type[100111], x[100111], y[100111], a[1011][1011], ans[100111];
void dfs(int v) {
  int value;
  if (type[v] == 1) {
    value = a[x[v]][y[v]];
    cnt -= a[x[v]][y[v]];
    a[x[v]][y[v]] = 1;
    cnt++;
  }
  if (type[v] == 2) {
    value = a[x[v]][y[v]];
    cnt -= a[x[v]][y[v]];
    a[x[v]][y[v]] = 0;
  }
  if (type[v] == 3) {
    for (int i = 1; i <= m; i++) {
      cnt -= a[x[v]][i];
      a[x[v]][i] ^= 1;
      cnt += a[x[v]][i];
    }
  }
  ans[v] = cnt;
  for (int i = 0; i < g[v].size(); i++) dfs(g[v][i]);
  if (type[v] == 1) {
    a[x[v]][y[v]] = value;
    cnt--;
    cnt += value;
  }
  if (type[v] == 2) {
    a[x[v]][y[v]] = value;
    cnt += value;
  }
  if (type[v] == 3) {
    for (int i = 1; i <= m; i++) {
      cnt -= a[x[v]][i];
      a[x[v]][i] ^= 1;
      cnt += a[x[v]][i];
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &type[i], &x[i]);
    if (type[i] <= 2) scanf("%d", &y[i]);
    if (type[i] == 4)
      g[x[i]].push_back(i);
    else
      g[i - 1].push_back(i);
  }
  dfs(0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
