#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> v[N];
int a[1001], b[1001][1001], sum[1001], ans = 0, m;
int q1[N], q2[N], q3[N], anss[N];
void dfs(int x) {
  for (int i : v[x]) {
    int y = 0;
    if (q1[i] == 1)
      if (b[q2[i]][q3[i]] == a[q2[i]]) {
        y = 1;
        b[q2[i]][q3[i]] = !b[q2[i]][q3[i]];
        sum[q2[i]]++;
        ans++;
      }
    if (q1[i] == 2)
      if (b[q2[i]][q3[i]] != a[q2[i]]) {
        y = 1;
        b[q2[i]][q3[i]] = !b[q2[i]][q3[i]];
        sum[q2[i]]--;
        ans--;
      }
    if (q1[i] == 3) {
      a[q2[i]] = !a[q2[i]];
      ans += -2 * sum[q2[i]] + m;
      sum[q2[i]] = m - sum[q2[i]];
    }
    anss[i] = ans;
    dfs(i);
    if (y) {
      b[q2[i]][q3[i]] = !b[q2[i]][q3[i]];
      if (q1[i] == 1) {
        sum[q2[i]]--;
        ans--;
      } else {
        sum[q2[i]]++;
        ans++;
      }
    }
    if (q1[i] == 3) {
      a[q2[i]] = !a[q2[i]];
      ans += -2 * sum[q2[i]] + m;
      sum[q2[i]] = m - sum[q2[i]];
    }
  }
}
int main() {
  int n, q, i;
  memset(a, 0, sizeof a);
  memset(b, 0, sizeof b);
  memset(sum, 0, sizeof sum);
  cin >> n >> m >> q;
  for (i = 1; i <= q; i++) {
    scanf("%d%d", q1 + i, q2 + i);
    if (q1[i] < 3) scanf("%d", q3 + i);
    if (q1[i] == 4)
      v[q2[i]].push_back(i);
    else
      v[i - 1].push_back(i);
  }
  dfs(0);
  for (i = 1; i <= q; i++) printf("%d\n", anss[i]);
  return 0;
}
