#include <bits/stdc++.h>
using namespace std;
struct seg {
  int l, r, v = 0;
  bool lz = false;
  seg *ch[2]{};
  seg(int _l, int _r) : l(_l), r(_r) {
    if (l < r - 1)
      ch[0] = new seg(l, l + r >> 1), ch[1] = new seg(l + r >> 1, r);
  }
  seg(seg *i) : l(i->l), r(i->r), v(i->v), lz(i->lz), ch{i->ch[0], i->ch[1]} {}
  seg *modify(int _l, int _r) {
    seg *copy = new seg(this);
    if (_l <= l && r <= _r) {
      copy->v = r - l - v, copy->lz ^= true;
      return copy;
    }
    copy->push();
    int m = l + r >> 1;
    if (_l < m) copy->ch[0] = copy->ch[0]->modify(_l, _r);
    if (m < _r) copy->ch[1] = copy->ch[1]->modify(_l, _r);
    copy->pull();
    return copy;
  }
  void push() {
    if (lz)
      ch[0] = ch[0]->modify(l, r), ch[1] = ch[1]->modify(l, r), lz = false;
  }
  void pull() { v = ch[0]->v + ch[1]->v; }
  seg *modify2(int i, int d) {
    seg *copy = new seg(this);
    if (l == r - 1) {
      copy->v = d;
      return copy;
    }
    copy->push();
    copy->ch[i >= l + r >> 1] = copy->ch[i >= l + r >> 1]->modify2(i, d);
    copy->pull();
    return copy;
  }
};
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<seg *> rts;
  rts.push_back(new seg(0, n * m));
  for (int i = 1; i <= q; ++i) {
    int ty, x;
    cin >> ty >> x;
    if (ty == 1) {
      int y;
      cin >> y;
      rts.push_back(rts.back()->modify2((x - 1) * m + y - 1, 1));
    } else if (ty == 2) {
      int y;
      cin >> y;
      rts.push_back(rts.back()->modify2((x - 1) * m + y - 1, 0));
    } else if (ty == 3)
      rts.push_back(rts.back()->modify((x - 1) * m, x * m));
    else
      rts.push_back(rts[x]);
    cout << rts.back()->v << '\n';
  }
}
