#include <bits/stdc++.h>
using namespace std;
const int COL = 1e3 + 2;
const int INF = INT_MAX / 3;
const int MOD = 1000000007;
vector<bitset<COL>> rows;
vector<vector<int>> version;
vector<int> ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  rows.push_back(bitset<COL>());
  vector<int> cur(n, 0);
  version.push_back(cur);
  ans.push_back(0);
  int cnt = 0;
  for (int i = 1; i <= q; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      int r, c;
      cin >> r >> c;
      r--;
      c--;
      int id = cur[r];
      if (rows[id][c] == 0) {
        rows.push_back(rows[id]);
        rows.back()[c] = 1;
        cnt++;
        cur[r] = rows.size() - 1;
      }
    } else if (op == 2) {
      int r, c;
      cin >> r >> c;
      r--;
      c--;
      int id = cur[r];
      if (rows[id][c] == 1) {
        rows.push_back(rows[id]);
        rows.back()[c] = 0;
        cnt--;
        cur[r] = rows.size() - 1;
      }
    } else if (op == 3) {
      int r;
      cin >> r;
      r--;
      int id = cur[r];
      rows.push_back(rows[id]);
      bitset<COL> t;
      t.set();
      t >>= (COL - m);
      cnt -= rows.back().count();
      rows.back() ^= t;
      cnt += rows.back().count();
      cur[r] = rows.size() - 1;
    } else {
      int k;
      cin >> k;
      cur = version[k];
      cnt = ans[k];
    }
    version.push_back(cur);
    ans.push_back(cnt);
    cout << cnt << '\n';
  }
}
