#include <bits/stdc++.h>
using namespace std;
long long n, m, q, t, st, prv, x, a, b;
long long mat[1005][1005];
long long cnt[1005];
long long arr[100005], ans[100005];
pair<long long, pair<long long, long long> > ins[100005];
vector<vector<pair<long long, long long> > > g;
vector<vector<long long> > tmp;
void dfs(long long cur, long long sum) {
  long long sz = tmp[cur].size();
  for (long long i = (long long)(0); i <= (long long)(sz - 1); i++)
    ans[tmp[cur][i]] = sum;
  sz = g[cur].size();
  for (long long i = (long long)(0); i <= (long long)(sz - 1); i++) {
    long long ty = g[cur][i].second;
    long long v = g[cur][i].first;
    long long r = ins[ty].second.first;
    long long c = ins[ty].second.second;
    if (ins[ty].first == 1) {
      if (mat[r][0] && mat[r][c] == 1) {
        mat[r][c] = 0;
        cnt[r]++;
        sum++;
        dfs(v, sum);
        cnt[r]--;
        sum--;
        mat[r][c] = 1;
      } else if (!mat[r][0] && mat[r][c] == 0) {
        mat[r][c] = 1;
        cnt[r]++;
        sum++;
        dfs(v, sum);
        cnt[r]--;
        sum--;
        mat[r][c] = 0;
      } else
        dfs(v, sum);
    }
    if (ins[ty].first == 2) {
      if (mat[r][0] && mat[r][c] == 0) {
        mat[r][c] = 1;
        cnt[r]--;
        sum--;
        dfs(v, sum);
        cnt[r]++;
        sum++;
        mat[r][c] = 0;
      } else if (!mat[r][0] && mat[r][c] == 1) {
        mat[r][c] = 0;
        cnt[r]--;
        sum--;
        dfs(v, sum);
        cnt[r]++;
        sum++;
        mat[r][c] = 1;
      } else
        dfs(v, sum);
    }
    if (ins[ty].first == 3) {
      long long p = cnt[r];
      long long p1 = sum;
      cnt[r] = m - cnt[r];
      long long dif = cnt[r] - p;
      sum = sum + dif;
      mat[r][0] = 1 - mat[r][0];
      dfs(v, sum);
      cnt[r] = p;
      sum = p1;
      mat[r][0] = 1 - mat[r][0];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  g = vector<vector<pair<long long, long long> > >(100005);
  tmp = vector<vector<long long> >(100005);
  tmp[0].push_back(0);
  for (long long i = (long long)(1); i <= (long long)(q); i++) {
    cin >> t;
    if (t != 4) {
      st++;
      arr[i] = st;
      g[prv].push_back({st, i});
      tmp[st].push_back(i);
      prv = st;
    } else {
      cin >> x;
      arr[i] = arr[x];
      tmp[arr[x]].push_back(i);
      prv = arr[x];
    }
    if (t <= 2) {
      cin >> a >> b;
      ins[i].first = t;
      ins[i].second.first = a;
      ins[i].second.second = b;
    } else if (t == 3) {
      cin >> a;
      ins[i].first = t;
      ins[i].second.first = a;
      ins[i].second.second = -1;
    }
  }
  dfs(0, 0);
  for (long long i = (long long)(1); i <= (long long)(q); i++)
    cout << ans[i] << endl;
  return 0;
}
