#include <bits/stdc++.h>
using namespace std;
int N, M, Q, Sum, op[100005], X[100005], Y[100005], Ans[100005], Mp[1005][1005],
    Lh[1005], Ln[1005];
int lnk[100005], nxt[100005], son[100005], tot;
bool vis[100005], Num[1005];
inline int read() {
  int N = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') ch = getchar();
  while (ch >= '0' && ch <= '9') N = N * 10 + ch - '0', ch = getchar();
  return N;
}
inline void add(int x, int y) {
  son[++tot] = y;
  nxt[tot] = lnk[x];
  lnk[x] = tot;
}
inline void fz(int x) {
  Sum += Ln[X[x]] - Lh[X[x]];
  Num[X[x]] ^= 1;
  swap(Ln[X[x]], Lh[X[x]]);
}
inline void work(int x) {
  if (op[x] == 1 && !(Mp[X[x]][Y[x]] ^ Num[X[x]]))
    Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++, vis[x] = 1;
  if (op[x] == 2 && Mp[X[x]][Y[x]] ^ Num[X[x]])
    Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--, vis[x] = 1;
  if (op[x] == 3) fz(x);
}
inline void rework(int x) {
  if (op[x] == 1 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--;
  if (op[x] == 2 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++;
  if (op[x] == 3) fz(x);
}
void DFS(int x) {
  work(x);
  Ans[x] = Sum;
  for (int i = lnk[x]; i; i = nxt[i]) DFS(son[i]);
  rework(x);
}
int main() {
  N = read();
  M = read();
  Q = read();
  for (int i = 1; i <= Q; i++) {
    op[i] = read();
    X[i] = read();
    if (op[i] <= 2) Y[i] = read();
    if (op[i] == 4)
      add(X[i], i);
    else
      add(i - 1, i);
  }
  for (int i = 1; i <= N; i++) Ln[i] = M;
  DFS(0);
  for (int i = 1; i <= Q; i++) printf("%d\n", Ans[i]);
  return 0;
}
