#include <bits/stdc++.h>
using namespace std;
int const maxn = 1100;
int const maxm = 100100;
struct node {
  int u, next;
};
node edge[maxm];
int head[maxm], p;
int op[maxm], x[maxm], y[maxm];
vector<vector<int> > matrix;
int res[maxm];
int n, m, q;
void add(int u, int v) {
  edge[p].next = head[u];
  head[u] = p;
  edge[p++].u = v;
}
void dfs(int u, int tot) {
  int flag = 0;
  if (op[u] == 1 && !matrix[x[u]][y[u]]) {
    flag = 1;
    matrix[x[u]][y[u]] = 1;
    tot++;
  } else if (op[u] == 2 && matrix[x[u]][y[u]]) {
    flag = 1;
    matrix[x[u]][y[u]] = 0;
    tot--;
  } else if (op[u] == 3) {
    flag = 1;
    for (int i = 0; i < m; i++) {
      tot += (matrix[x[u]][i] == 1 ? -1 : 1);
      matrix[x[u]][i] ^= 1;
    }
  }
  res[u] = tot;
  for (int i = head[u]; i != -1; i = edge[i].next) dfs(edge[i].u, tot);
  if (flag) {
    if (op[u] == 1) {
      matrix[x[u]][y[u]] = 0;
      tot--;
    }
    if (op[u] == 2) {
      matrix[x[u]][y[u]] = 1;
      tot++;
    }
    if (op[u] == 3) {
      for (int i = 0; i < m; i++) {
        tot += (matrix[x[u]][i] == 1 ? -1 : 1);
        matrix[x[u]][i] ^= 1;
      }
    }
  }
}
int main() {
  cin >> n >> m >> q;
  matrix.resize(n, vector<int>(m, 0));
  memset(head, -1, sizeof(head));
  p = 0;
  for (int i = 0; i < q; i++) {
    cin >> op[i + 1] >> x[i + 1];
    if (op[i + 1] < 3) cin >> y[i + 1];
    if (op[i + 1] == 4)
      add(x[i + 1], i + 1);
    else {
      x[i + 1]--;
      if (op[i + 1] != 3) y[i + 1]--;
      add(i, i + 1);
    }
  }
  op[0] = 0;
  dfs(0, 0);
  for (int i = 0; i < q; i++) cout << res[i + 1] << "\n";
  return 0;
}
