#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int x = powmod(a, b / 2);
  long long int y = (x * x) % 1000000007;
  if (b % 2) return (a * y) % 1000000007;
  return y % 1000000007;
}
int n, m, q;
vector<int> g[100010];
bool check[1002][1002], changed[100010];
pair<int, pair<int, int> > Query[100010];
int cnt;
int ans[100010];
inline void Do(int u) {
  int t = Query[u].first, i = Query[u].second.first, j = Query[u].second.second;
  if (t == 1) {
    if (!check[i][j]) {
      check[i][j] = true;
      changed[u] = true;
      cnt++;
    }
  }
  if (t == 2) {
    if (check[i][j]) {
      check[i][j] = false;
      changed[u] = true;
      cnt--;
    }
  }
  if (t == 3) {
    for (int k = 1; k < m + 1; k++) {
      if (check[i][k])
        check[i][k] = false, cnt--;
      else
        check[i][k] = true, cnt++;
    }
  }
}
inline void Undo(int u) {
  int t = Query[u].first, i = Query[u].second.first, j = Query[u].second.second;
  if (t == 1) {
    if (changed[u]) {
      check[i][j] = false;
      cnt--;
    }
  }
  if (t == 2) {
    if (changed[u]) {
      check[i][j] = true;
      cnt++;
    }
  }
  if (t == 3) {
    for (int k = 1; k < m + 1; k++) {
      if (check[i][k])
        check[i][k] = false, cnt--;
      else
        check[i][k] = true, cnt++;
    }
  }
}
inline void dfs(int u) {
  Do(u);
  ans[u] = cnt;
  for (int v : g[u]) dfs(v);
  Undo(u);
}
int main() {
  scanf("%d", &n), scanf("%d", &m), scanf("%d", &q);
  for (int i = 1; i < q + 1; i++) {
    int t;
    scanf("%d", &t);
    if (t <= 2) {
      int x, y;
      scanf("%d", &x), scanf("%d", &y);
      Query[i] = make_pair(t, make_pair(x, y));
      g[i - 1].push_back(i);
    } else if (t == 3) {
      int x;
      scanf("%d", &x);
      Query[i] = make_pair(t, make_pair(x, -1));
      g[i - 1].push_back(i);
    } else {
      int x;
      scanf("%d", &x);
      Query[i] = make_pair(t, make_pair(x, -1));
      g[x].push_back(i);
    }
  }
  dfs(0);
  for (int i = 1; i < q + 1; i++) printf("%d\n", ans[i]);
  return 0;
}
