#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int M = 1e3 + 7;
int used = 1;
bitset<M> row[N];
vector<int> v[N];
int sum[N];
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  v[0].resize(n, 0);
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 4) {
      int x;
      cin >> x;
      v[i + 1] = v[x];
      sum[i + 1] = sum[x];
    } else {
      int r;
      cin >> r;
      r--;
      v[i + 1] = v[i];
      v[i + 1][r] = used;
      row[used] = row[v[i][r]];
      if (t == 3)
        for (int j = 0; j < m; j++) row[used][j] = row[used][j] ^ 1;
      else {
        int c;
        cin >> c;
        c--;
        if (t == 1)
          row[used][c] = 1;
        else
          row[used][c] = 0;
      }
      sum[i + 1] = sum[i] - row[v[i][r]].count() + row[used].count();
      used++;
    }
    cout << sum[i + 1] << "\n";
  }
}
