#include <bits/stdc++.h>
using namespace std;
const int MAX = 100010;
const int MAXN = 1010;
struct Node {
  int x, y, z;
} p[MAX];
vector<int> G[MAX];
int mark[MAXN][MAXN];
int d[MAX], n, m, q;
void init() {
  d[0] = 0;
  memset(mark, 0, sizeof(mark));
  for (int i = 0; i < MAX; i++) G[i].clear();
}
void dfs(int u) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    int s = p[v].y, t = p[v].z;
    if (p[v].x == 1) {
      if (mark[s][t] == 1) {
        d[v] = d[u];
        dfs(v);
      } else {
        mark[s][t] = 1;
        d[v] = d[u] + 1;
        dfs(v);
        mark[s][t] = 0;
      }
    }
    if (p[v].x == 2) {
      if (mark[s][t] == 0) {
        d[v] = d[u];
        dfs(v);
      } else {
        mark[s][t] = 0;
        d[v] = d[u] - 1;
        dfs(v);
        mark[s][t] = 1;
      }
    }
    if (p[v].x == 3) {
      int cnt = 0;
      for (int j = 1; j <= m; j++) {
        if (mark[s][j] == 1) {
          cnt--;
          mark[s][j] = 0;
        } else {
          cnt++;
          mark[s][j] = 1;
        }
      }
      d[v] = d[u] + cnt;
      dfs(v);
      for (int j = 1; j <= m; j++) {
        if (mark[s][j] == 0) {
          mark[s][j] = 1;
        } else {
          mark[s][j] = 0;
        }
      }
    }
    if (p[v].x == 4) {
      d[v] = d[u];
      dfs(v);
    }
  }
}
int main() {
  while (scanf("%d%d%d", &n, &m, &q) != EOF) {
    init();
    for (int i = 1; i <= q; i++) {
      scanf("%d", &p[i].x);
      if (p[i].x == 1 || p[i].x == 2) {
        scanf("%d%d", &p[i].y, &p[i].z);
        G[i - 1].push_back(i);
      }
      if (p[i].x == 3) {
        scanf("%d", &p[i].y);
        G[i - 1].push_back(i);
      }
      if (p[i].x == 4) {
        scanf("%d", &p[i].y);
        G[p[i].y].push_back(i);
      }
    }
    dfs(0);
    for (int i = 1; i <= q; i++) printf("%d\n", d[i]);
  }
  return 0;
}
