#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, LIMIT = 1e9 + 7, Nn = 1e3 + 5;
struct Node {
  int type, x, y;
};
vector<int> a[N];
Node query[N];
bool vis[N];
int ans[N], c[Nn][Nn];
int n, m, q, res = 0;
void Read() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(c, 0, sizeof(c));
  cin >> n >> m >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> query[i].type;
    if (query[i].type < 3) {
      cin >> query[i].x >> query[i].y;
      a[i - 1].push_back(i);
    } else {
      cin >> query[i].x;
      query[i].y = -1;
      if (query[i].type == 3) {
        a[i - 1].push_back(i);
      } else
        a[query[i].x].push_back(i);
    }
  }
}
void Dfs(int x) {
  vis[x] = true;
  for (int i = 0; i < a[x].size(); ++i) {
    int v = a[x][i];
    if (!vis[v]) {
      Node u = query[v];
      if (u.type == 1) {
        if (c[u.x][u.y] == 0) {
          ++res;
          c[u.x][u.y] = 1;
          ans[v] = res;
          Dfs(v);
          --res;
          c[u.x][u.y] = 0;
        } else {
          ans[v] = res;
          Dfs(v);
        }
      } else if (u.type == 2) {
        if (c[u.x][u.y] == 1) {
          --res;
          c[u.x][u.y] = 0;
          ans[v] = res;
          Dfs(v);
          ++res;
          c[u.x][u.y] = 1;
        } else {
          ans[v] = res;
          Dfs(v);
        }
      } else if (u.type == 3) {
        for (int i = 1; i <= m; ++i) {
          if (c[u.x][i] == 0) {
            ++res;
            c[u.x][i] = 1;
          } else {
            --res;
            c[u.x][i] = 0;
          }
        }
        ans[v] = res;
        Dfs(v);
        for (int i = 1; i <= m; ++i) {
          if (c[u.x][i] == 0) {
            ++res;
            c[u.x][i] = 1;
          } else {
            --res;
            c[u.x][i] = 0;
          }
        }
      } else {
        ans[v] = res;
        Dfs(v);
      }
    }
  }
}
void Print() {
  for (int i = 1; i <= q; ++i) {
    cout << ans[i] << "\n";
  }
}
int main() {
  Read();
  Dfs(0);
  Print();
  return 0;
}
