#include <bits/stdc++.h>
using namespace std;
struct query {
  int t, i, j, k, id;
};
query q[100005];
int parent[100005];
vector<int> g[100005];
int ans[100005];
int n, m, qq;
bool a[1005][1005];
int total = 0;
void printA() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << a[i][j];
    cout << endl;
  }
}
void dfs(int x) {
  for (const int y : g[x]) {
    int t = q[y].t;
    int was = -1;
    if (t == 1) {
      int i = q[y].i;
      int j = q[y].j;
      if (!a[i][j]) {
        was = 0;
        a[i][j] = true;
        total++;
      }
    }
    if (t == 2) {
      int i = q[y].i;
      int j = q[y].j;
      if (a[i][j]) {
        was = 1;
        a[i][j] = false;
        total--;
      }
    }
    if (t == 3) {
      int i = q[y].i;
      for (int j = 1; j <= m; j++) {
        if (a[i][j]) {
          total--;
        } else {
          total++;
        }
        a[i][j] ^= true;
      }
    }
    ans[y] = total;
    dfs(y);
    if (t == 1) {
      int i = q[y].i;
      int j = q[y].j;
      if (was == 0) {
        a[i][j] = false;
        total--;
      }
    }
    if (t == 2) {
      int i = q[y].i;
      int j = q[y].j;
      if (was == 1) {
        a[i][j] = true;
        total++;
      }
    }
    if (t == 3) {
      int i = q[y].i;
      for (int j = 1; j <= m; j++) {
        if (a[i][j]) {
          total--;
        } else {
          total++;
        }
        a[i][j] ^= true;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  memset(a, 0, sizeof(a));
  cin >> n >> m >> qq;
  for (int id = 1; id <= qq; id++) {
    cin >> q[id].t;
    switch (q[id].t) {
      case 1:
        cin >> q[id].i >> q[id].j;
        parent[id] = id - 1;
        break;
      case 2:
        cin >> q[id].i >> q[id].j;
        parent[id] = id - 1;
        break;
      case 3:
        cin >> q[id].i;
        parent[id] = id - 1;
        break;
      case 4:
        cin >> q[id].k;
        parent[id] = q[id].k;
        break;
    }
  }
  for (int i = 1; i <= qq; i++) {
    g[parent[i]].push_back(i);
  }
  dfs(0);
  for (int id = 1; id <= qq; id++) {
    cout << ans[id] << '\n';
  }
}
