#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 9223372036854775807;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
}
struct node {
  int sum;
  node *l, *r;
  node() {
    l = r = NULL;
    sum = 0;
  }
  node(int _sum) {
    sum = _sum;
    l = r = NULL;
  }
} * T[4 * Sz][3];
node *build(int v, int tl, int tr, int x) {
  if (tl == tr) return new node(x);
  node *t = new node(0);
  int mid = (tl + tr) / 2;
  t->l = build(2 * v, tl, mid, x);
  t->r = build(2 * v + 1, mid + 1, tr, x);
  t->sum = t->l->sum + t->r->sum;
  return t;
}
node *update(node *&t, int v, int tl, int tr, int pos, int val) {
  if (tl == tr) return new node(val);
  int mid = (tl + tr) / 2;
  node *nt = new node(0);
  if (pos <= mid) {
    nt->l = update(t->l, 2 * v, tl, mid, pos, val);
    nt->r = t->r;
  } else {
    nt->r = update(t->r, 2 * v + 1, mid + 1, tr, pos, val);
    nt->l = t->l;
  }
  nt->sum = nt->l->sum + nt->r->sum;
  return nt;
}
node *get(node *&A, node *&B, int v, int tl, int tr, int l, int r) {
  if (l > tr || r < tl) return A;
  if (l <= tl && tr <= r) return B;
  node *nt = new node(0);
  int mid = (tl + tr) / 2;
  nt->l = get(A->l, B->l, 2 * v, tl, mid, l, r);
  nt->r = get(A->r, B->r, 2 * v + 1, mid + 1, tr, l, r);
  nt->sum = nt->l->sum + nt->r->sum;
  return nt;
}
int n, m, q;
inline int p(int x, int y) { return (x - 1) * m + y; }
inline void q1(int i, int pos) {
  T[i][1] = T[i - 1][1];
  T[i][2] = T[i - 1][2];
  T[i][1] = update(T[i][1], 1, 1, n * m, pos, 1);
  T[i][2] = update(T[i][2], 1, 1, n * m, pos, 0);
}
inline void q2(int i, int pos) {
  T[i][1] = T[i - 1][1];
  T[i][2] = T[i - 1][2];
  T[i][1] = update(T[i][1], 1, 1, n * m, pos, 0);
  T[i][2] = update(T[i][2], 1, 1, n * m, pos, 1);
}
inline void q3(int i, int block) {
  T[i][1] = T[i - 1][1];
  T[i][2] = T[i - 1][2];
  int l = (block - 1) * m + 1, r = block * m;
  node *A = T[i][1], *B = T[i][2];
  T[i][1] = get(A, B, 1, 1, n * m, l, r);
  T[i][2] = get(B, A, 1, 1, n * m, l, r);
}
inline void q4(int i, int k) {
  T[i][1] = T[k][1];
  T[i][2] = T[k][2];
}
int main() {
  Read_rap();
  cin >> n >> m >> q;
  T[0][1] = build(1, 1, n * m, 0);
  T[0][2] = build(1, 1, n * m, 1);
  for (int i = 1; i <= q; i++) {
    int tp, x;
    cin >> tp >> x;
    if (tp == 1) {
      int y;
      cin >> y;
      q1(i, p(x, y));
    }
    if (tp == 2) {
      int y;
      cin >> y;
      q2(i, p(x, y));
    }
    if (tp == 3) q3(i, x);
    if (tp == 4) q4(i, x);
    cout << T[i][1]->sum << '\n';
  }
  return 0;
}
