#include <bits/stdc++.h>
using namespace std;
unsigned next() {
  static unsigned x(987654321), y(123456789), z(521288629), w(136751267);
  unsigned t = x ^ x << 11;
  x = y, y = z, z = w;
  return w = ((t ^ t >> 8) ^ w) ^ w >> 19;
}
long long f(long long t) {
  long long ans = 1LL;
  for (int i = 1; i <= t; i++) ans *= i;
  return ans;
}
const int N = 1e5 + 10;
vector<int> G[N];
bool M[1010][1010];
int m;
int type[N], row[N], col[N], ans[N];
void dfs(int u) {
  for (int v : G[u]) {
    ans[v] = ans[u];
    bool check = false;
    if (type[v] == 1) {
      ans[v] += (!M[row[v]][col[v]]);
      check |= (!M[row[v]][col[v]]);
      M[row[v]][col[v]] = true;
    }
    if (type[v] == 2) {
      ans[v] -= (M[row[v]][col[v]]);
      check |= (M[row[v]][col[v]]);
      M[row[v]][col[v]] = false;
    }
    if (type[v] == 3) {
      for (int i = 1; i <= m; i++) {
        ans[v] -= (M[row[v]][i] ? 1 : -1);
        M[row[v]][i] ^= 1;
      }
    }
    dfs(v);
    if (type[v] == 4) continue;
    if (type[v] == 3) {
      for (int i = 1; i <= m; i++) {
        M[row[v]][i] ^= 1;
      }
      continue;
    }
    M[row[v]][col[v]] ^= check;
  }
}
int main() {
  int n, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    cin >> type[i];
    if (type[i] <= 2) {
      cin >> row[i] >> col[i];
    } else
      cin >> row[i];
    if (type[i] == 4)
      G[row[i]].push_back(i);
    else
      G[i - 1].push_back(i);
  }
  dfs(0);
  for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
}
