#include <bits/stdc++.h>
using namespace std;
inline void print(char pt) { printf("%c\n", pt); }
inline void print(int pt) { printf("%d\n", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%.1f\n", pt); }
inline void print(char pt[]) { printf("%s\n", pt); }
inline void print() { printf("\n"); }
inline void scan(int &pt) { scanf("%d", &pt); }
inline void scan(char &pt) { scanf("%c", &pt); }
inline void scan(long long &pt) { scanf("%I64d", &pt); }
inline void scan(double &pt) { scanf("%lf", &pt); }
inline void scan(char pt[]) { scanf("%s", pt); }
void fail() {
  print(-1);
  exit(0);
}
int suma;
struct node {
  int suma;
  int ifreverse;
  bitset<1008> sons;
};
node nodes[1008];
int n, m, q;
struct treenode {
  int self;
  int father;
  int ifdo;
  vector<int> sons;
  int t, l, r;
};
treenode tns[100008];
int ansa[100008];
void dfs(int nowpos, int fromfather) {
  if (nowpos == -1) return;
  if (fromfather) {
    if (tns[nowpos].t == 1) {
      if ((nodes[tns[nowpos].l].sons[tns[nowpos].r] +
           nodes[tns[nowpos].l].ifreverse) %
              2 ==
          0) {
        nodes[tns[nowpos].l].sons.flip(tns[nowpos].r);
        nodes[tns[nowpos].l].suma++;
        suma++;
        tns[nowpos].ifdo = 1;
      }
    }
    if (tns[nowpos].t == 2) {
      if ((nodes[tns[nowpos].l].sons[tns[nowpos].r] +
           nodes[tns[nowpos].l].ifreverse) %
              2 ==
          1) {
        nodes[tns[nowpos].l].sons.flip(tns[nowpos].r);
        nodes[tns[nowpos].l].suma--;
        suma--;
        tns[nowpos].ifdo = 1;
      }
    }
    if (tns[nowpos].t == 3) {
      nodes[tns[nowpos].l].ifreverse = !(nodes[tns[nowpos].l].ifreverse);
      suma += m - nodes[tns[nowpos].l].suma * 2;
      nodes[tns[nowpos].l].suma = m - nodes[tns[nowpos].l].suma;
      tns[nowpos].ifdo = 1;
    }
  }
  ansa[nowpos] = suma;
  if (tns[nowpos].sons.size() == 0) {
    if (tns[nowpos].ifdo == 1) {
      if (tns[nowpos].t == 2) {
        nodes[tns[nowpos].l].sons.flip(tns[nowpos].r);
        nodes[tns[nowpos].l].suma++;
        suma++;
      }
      if (tns[nowpos].t == 1) {
        nodes[tns[nowpos].l].sons.flip(tns[nowpos].r);
        nodes[tns[nowpos].l].suma--;
        suma--;
      }
      if (tns[nowpos].t == 3) {
        nodes[tns[nowpos].l].ifreverse = !(nodes[tns[nowpos].l].ifreverse);
        suma += m - nodes[tns[nowpos].l].suma * 2;
        nodes[tns[nowpos].l].suma = m - nodes[tns[nowpos].l].suma;
      }
    }
    dfs(tns[nowpos].father, 0);
    return;
  }
  int nowson = (tns[nowpos].sons.back());
  tns[nowpos].sons.pop_back();
  dfs(nowson, 1);
  return;
}
int main() {
  scan(n);
  scan(m);
  scan(q);
  tns[0].father = -1;
  for (int i = 1; i <= q; i++) {
    tns[i].self = i;
    scan(tns[i].t);
    scan(tns[i].l);
    if (tns[i].t <= 2) {
      scan(tns[i].r);
    }
    if (tns[i].t == 4) {
      tns[tns[i].l].sons.push_back(i);
      tns[i].father = tns[i].l;
    } else {
      tns[i - 1].sons.push_back(i);
      tns[i].father = i - 1;
    }
  }
  dfs(1, 1);
  for (int i = 1; i <= q; i++) {
    print(ansa[i]);
  }
  return 0;
}
