#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void output(T a, int p) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
struct query {
  int type, i, j, k;
};
int N, M, Q, sum = 0;
vector<vector<int>> G, book;
vector<query> A;
vector<int> ret, cnt, inv, diff;
void exec_query(int cur, int rev = 0) {
  query q = A[cur - 1];
  if (rev) {
    if (q.type == 1)
      q.type = 2;
    else if (q.type == 2)
      q.type = 1;
  }
  if (q.type == 1) {
    if (rev && diff[cur - 1] == 0) return;
    if (rev && diff[cur - 1] == 1) {
      if (book[q.i][q.j] == 0)
        book[q.i][q.j] = 1, cnt[q.i]++, sum++;
      else
        book[q.i][q.j] = 0, cnt[q.i]--, sum++;
      return;
    }
    if (book[q.i][q.j] == 0 && inv[q.i] > 0)
      book[q.i][q.j] = 1, cnt[q.i]++, sum++, diff[cur - 1] = 1;
    if (book[q.i][q.j] == 1 && inv[q.i] < 0)
      book[q.i][q.j] = 0, cnt[q.i]--, sum++, diff[cur - 1] = 1;
  } else if (q.type == 2) {
    if (rev && diff[cur - 1] == 0) return;
    if (rev && diff[cur - 1] == 1) {
      if (book[q.i][q.j] == 0)
        book[q.i][q.j] = 1, cnt[q.i]++, sum--;
      else
        book[q.i][q.j] = 0, cnt[q.i]--, sum--;
      return;
    }
    if (book[q.i][q.j] == 1 && inv[q.i] > 0)
      book[q.i][q.j] = 0, cnt[q.i]--, sum--, diff[cur - 1] = 1;
    if (book[q.i][q.j] == 0 && inv[q.i] < 0)
      book[q.i][q.j] = 1, cnt[q.i]++, sum--, diff[cur - 1] = 1;
  } else if (q.type == 3) {
    if (inv[q.i] > 0)
      sum += M - 2 * cnt[q.i];
    else
      sum += 2 * cnt[q.i] - M;
    inv[q.i] = -inv[q.i];
  }
  return;
}
void dfs(int cur = 0) {
  for (int v : G[cur]) {
    exec_query(v);
    ret[v] = sum;
    dfs(v);
    exec_query(v, 1);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> N >> M >> Q;
  G.resize(Q + 1);
  A.resize(Q);
  book.assign(N, vector<int>(M, 0));
  cnt.assign(N, 0);
  inv.assign(N, 1);
  diff.assign(Q, 0);
  ret.assign(Q + 1, 0);
  for (int i = (int)(0); i < (int)(Q); i++) {
    int type;
    cin >> type;
    if (type == 1 || type == 2) {
      int qi, qj;
      cin >> qi >> qj;
      qi--, qj--;
      A[i] = query{type, qi, qj, -1};
      G[i].push_back(i + 1);
    } else if (type == 3) {
      int qi;
      cin >> qi;
      qi--;
      A[i] = query{type, qi, -1, -1};
      G[i].push_back(i + 1);
    } else {
      int qk;
      cin >> qk;
      A[i] = query{type, -1, -1, qk};
      G[qk].push_back(i + 1);
    }
  }
  dfs();
  for (int i = (int)(1); i < (int)(Q + 1); i++) output(ret[i], 0);
  return 0;
}
