#include <bits/stdc++.h>
const int N = 1e3 + 5;
const int Q = 1e5 + 5;
int a[N][N];
int emp[N], s[N];
struct Data {
  int tp, x, y;
} data[Q];
std::vector<int> edge[Q];
int ans[Q];
bool fail[Q];
int n, m, q;
int sum;
void work(int id) {
  Data &d = data[id];
  if (d.tp == 1) {
    if (a[d.x][d.y] == emp[d.x]) {
      a[d.x][d.y] = 1 ^ emp[d.x];
      s[d.x]++;
      sum++;
    } else
      fail[id] = true;
  } else if (d.tp == 2) {
    if (a[d.x][d.y] != emp[d.x]) {
      a[d.x][d.y] = emp[d.x];
      s[d.x]--;
      sum--;
    } else
      fail[id] = true;
  } else {
    sum = sum - s[d.x] + (m - s[d.x]);
    s[d.x] = m - s[d.x];
    emp[d.x] ^= 1;
  }
}
void undo(int id) {
  if (fail[id]) return;
  Data &d = data[id];
  if (d.tp == 1) {
    if (a[d.x][d.y] != emp[d.x]) {
      a[d.x][d.y] = emp[d.x];
      s[d.x]--;
      sum--;
    }
  } else if (d.tp == 2) {
    if (a[d.x][d.y] == emp[d.x]) {
      a[d.x][d.y] = 1 ^ emp[d.x];
      s[d.x]++;
      sum++;
    }
  } else {
    sum = sum - s[d.x] + (m - s[d.x]);
    s[d.x] = m - s[d.x];
    emp[d.x] ^= 1;
  }
}
void back(int from, int to) {
  for (int i = from; i >= to; --i) {
    undo(i);
  }
}
int travel(int from) {
  for (int i = from; i <= q; ++i) {
    if (i > from && data[i].tp == 4) return i;
    if (i > from) work(i);
    ans[i] = sum;
    for (int j = 0; j < edge[i].size(); ++j) {
      int bg = edge[i][j];
      if (ans[bg] != -1) continue;
      int ed = travel(bg);
      back(ed - 1, bg + 1);
    }
  }
  return q + 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  int tp, x, y, k;
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &tp);
    if (tp <= 2) {
      scanf("%d%d", &x, &y);
      data[i] = {tp, x, y};
    } else if (tp == 3) {
      scanf("%d", &x);
      data[i] = {tp, x, -1};
    } else {
      scanf("%d", &k);
      data[i] = {tp, -1, -1};
      edge[k].push_back(i);
    }
  }
  memset(ans, -1, sizeof(ans));
  ans[0] = 0;
  sum = 0;
  for (int i = 0; i <= q; ++i) {
    if (i > 0 && ans[i] != -1) {
      printf("%d\n", ans[i]);
    } else if (i > 0) {
      work(i);
      ans[i] = sum;
      printf("%d\n", ans[i]);
    }
    for (int j = 0; j < edge[i].size(); ++j) {
      int bg = edge[i][j];
      if (ans[bg] != -1) continue;
      int ed = travel(bg);
      back(ed - 1, bg + 1);
    }
  }
  return 0;
}
