#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1005;
const int M = 100005;
int n, m, q;
int a[N][N], sum;
int invert[N], sumRow[N];
pair<int, pair<int, int> > query[M];
vector<int> adj[M];
int ans[M];
void dfs(int u) {
  int type = query[u].first;
  int preState, preVal, preRow, preSum;
  if (type == 1) {
    int x = query[u].second.first, y = query[u].second.second;
    preVal = a[x][y], preRow = sumRow[x], preSum = sum;
    if (invert[x] == 0) {
      if (a[x][y] == 0) {
        a[x][y] = 1;
        sumRow[x]++;
        sum++;
      }
    } else {
      if (a[x][y] == 1) {
        a[x][y] = 0;
        sumRow[x]++;
        sum++;
      }
    }
  } else if (type == 2) {
    int x = query[u].second.first, y = query[u].second.second;
    preVal = a[x][y], preRow = sumRow[x], preSum = sum;
    if (invert[x] == 0) {
      if (a[x][y] == 1) {
        a[x][y] = 0;
        sumRow[x]--;
        sum--;
      }
    } else {
      if (a[x][y] == 0) {
        a[x][y] = 1;
        sumRow[x]--;
        sum--;
      }
    }
  } else if (type == 3) {
    int x = query[u].second.first;
    preState = invert[x], preRow = sumRow[x], preSum = sum;
    invert[x] ^= 1;
    sum += m - 2 * sumRow[x];
    sumRow[x] = m - sumRow[x];
  }
  ans[u] = sum;
  for (int v : adj[u]) dfs(v);
  if (type == 1) {
    int x = query[u].second.first, y = query[u].second.second;
    a[x][y] = preVal;
    sumRow[x] = preRow;
    sum = preSum;
  } else if (type == 2) {
    int x = query[u].second.first, y = query[u].second.second;
    a[x][y] = preVal;
    sumRow[x] = preRow;
    sum = preSum;
  } else if (type == 3) {
    int x = query[u].second.first;
    invert[x] = preState;
    sumRow[x] = preRow;
    sum = preSum;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int x, y;
      cin >> x >> y;
      adj[i - 1].push_back(i);
      query[i] = {1, {x, y}};
    } else if (type == 2) {
      int x, y;
      cin >> x >> y;
      adj[i - 1].push_back(i);
      query[i] = {2, {x, y}};
    } else if (type == 3) {
      int id;
      cin >> id;
      adj[i - 1].push_back(i);
      query[i] = {3, {id, 0}};
    } else {
      int k;
      cin >> k;
      adj[k].push_back(i);
      query[i] = {4, {k, 0}};
    }
  }
  dfs(0);
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
}
