#include <bits/stdc++.h>
using namespace std;
int const INF = numeric_limits<int>::max();
long long const LLINF = numeric_limits<long long>::max();
int const N = 1e5 + 5;
int const M = 1e3 + 5;
set<int> next_version[N];
bool a[M][M];
int ans[N];
int sum = 0;
int queries[N][3];
int n, m, q;
void dfs(int ver) {
  if (ver > q) {
    return;
  }
  for (int nv : next_version[ver]) {
    int t = queries[nv][0];
    int i = queries[nv][1], j = queries[nv][2];
    if (t == 1) {
      bool flag = false;
      if (!a[i][j]) {
        a[i][j] = true;
        sum++;
        flag = true;
      }
      ans[nv] = sum;
      dfs(nv);
      if (flag) {
        a[i][j] = false;
        sum--;
      }
    } else if (t == 2) {
      bool flag = false;
      if (a[i][j]) {
        a[i][j] = false;
        sum--;
        flag = true;
      }
      ans[nv] = sum;
      dfs(nv);
      if (flag) {
        a[i][j] = true;
        sum++;
      }
    } else if (t == 3) {
      for (int j = 1; j <= m; j++) {
        if (a[i][j]) {
          sum--;
        } else {
          sum++;
        }
        a[i][j] = !a[i][j];
      }
      ans[nv] = sum;
      dfs(nv);
      for (int j = 1; j <= m; j++) {
        if (a[i][j]) {
          sum--;
        } else {
          sum++;
        }
        a[i][j] = !a[i][j];
      }
    } else {
      ans[nv] = sum;
      dfs(nv);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  for (int i = 0; i <= q; i++) {
    next_version[i].insert(i + 1);
  }
  for (int i = 1; i <= q; i++) {
    cin >> queries[i][0];
    if (queries[i][0] == 1 || queries[i][0] == 2) {
      cin >> queries[i][1] >> queries[i][2];
    } else {
      cin >> queries[i][1];
    }
    if (queries[i][0] == 4) {
      next_version[i - 1].erase(i);
      next_version[queries[i][1]].insert(i);
    }
  }
  fill(ans, ans + N, -1);
  dfs(0);
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
