#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct Ope {
  int com;
  int x, y;
} Q[N];
vector<int> ch[N];
bool sh[1005][1005];
int ans[N], cnt, n, m, q;
void dfs(int u) {
  bool flag = 0;
  if (Q[u].com == 1) {
    if (sh[Q[u].x][Q[u].y] == 0) sh[Q[u].x][Q[u].y] = 1, cnt++, flag = 1;
  } else if (Q[u].com == 2) {
    if (sh[Q[u].x][Q[u].y] == 1) sh[Q[u].x][Q[u].y] = 0, cnt--, flag = 1;
  } else if (Q[u].com == 3) {
    flag = 1;
    for (int i = 1; i <= m; i++)
      if (sh[Q[u].x][i] == 0)
        cnt++, sh[Q[u].x][i] = 1;
      else
        cnt--, sh[Q[u].x][i] = 0;
  }
  ans[u] = cnt;
  for (int i = 0, len = ch[u].size(); i < len; i++) dfs(ch[u][i]);
  if (!flag) return;
  if (Q[u].com == 1)
    sh[Q[u].x][Q[u].y] = 0, cnt--;
  else if (Q[u].com == 2)
    sh[Q[u].x][Q[u].y] = 1, cnt++;
  else if (Q[u].com == 3)
    for (int i = 1; i <= m; i++)
      if (sh[Q[u].x][i] == 0)
        cnt++, sh[Q[u].x][i] = 1;
      else
        cnt--, sh[Q[u].x][i] = 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &Q[i].com);
    if (Q[i].com <= 2)
      scanf("%d%d", &Q[i].x, &Q[i].y), ch[i - 1].push_back(i);
    else {
      scanf("%d", &Q[i].x);
      if (Q[i].com == 4)
        ch[Q[i].x].push_back(i);
      else
        ch[i - 1].push_back(i);
    }
  }
  dfs(0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
