#include <bits/stdc++.h>
using namespace std;
const int Q = 1e5 + 5;
const int M = 1e3 + 5;
struct str_comand {
  int type, first, second, ans;
  vector<int> next;
};
str_comand cmd[Q];
bitset<M> box[M];
int n, m, q, total = 0;
void dfs(int);
void go_by(int i) {
  cmd[i].ans = total;
  for (int j = 0; j < cmd[i].next.size(); j++) {
    dfs(cmd[i].next[j]);
  }
}
void dfs(int x) {
  if (cmd[x].type == 1) {
    int i = cmd[x].first;
    int j = cmd[x].second;
    bool test = box[i][j] == false;
    if (test) {
      total++;
    }
    box[i][j] = true;
    go_by(x);
    if (test) {
      total--;
      box[i][j] = false;
    }
  } else if (cmd[x].type == 2) {
    int i = cmd[x].first;
    int j = cmd[x].second;
    bool test = box[i][j] == true;
    if (test) {
      total--;
    }
    box[i][j] = false;
    go_by(x);
    if (test) {
      total++;
      box[i][j] = true;
    }
  } else if (cmd[x].type == 3) {
    int i = cmd[x].first;
    total -= box[i].count();
    box[i].flip();
    for (int j = m; j < M; j++) {
      box[i][j] = 0;
    }
    total += box[i].count();
    go_by(x);
    total -= box[i].count();
    box[i].flip();
    for (int j = m; j < M; j++) {
      box[i][j] = 0;
    }
    total += box[i].count();
  } else {
    go_by(x);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    cin >> cmd[i].type >> cmd[i].first;
    cmd[i].first--;
    if (cmd[i].type < 3) {
      cin >> cmd[i].second;
      cmd[i].second--;
    }
    if (cmd[i].type == 4) {
      cmd[cmd[i].first + 1].next.push_back(i);
    } else {
      cmd[i - 1].next.push_back(i);
    }
  }
  go_by(0);
  for (int i = 1; i <= q; i++) {
    cout << cmd[i].ans << "\n";
  }
  return 0;
}
