#include <bits/stdc++.h>
using namespace std;
int N, M;
struct node {
  node *L, *R;
  int si, sj;
  int total = 0;
  bitset<1000> B;
  node() {}
  node(int i, int j, node* a, node* b) {
    si = i;
    sj = j;
    L = a;
    R = b;
  }
};
node* build(int i, int j) {
  if (i == j) {
    return new node(i, j, NULL, NULL);
  } else {
    int mid = (i + j) / 2;
    node* L = build(i, mid);
    node* R = build(mid + 1, j);
    return new node(i, j, L, R);
  }
}
node* tree[100000 + 5];
void update(node* old, node* cur, int i, int j, int bit) {
  if (old->si == old->sj) {
    cur->B = old->B;
    cur->B[j - 1] = bit;
    cur->total = cur->B.count();
  } else {
    int si = old->si;
    int sj = old->sj;
    int m = (si + sj) / 2;
    if (i <= m) {
      cur->R = old->R;
      cur->L = new node(si, m, NULL, NULL);
      update(old->L, cur->L, i, j, bit);
    } else {
      cur->L = old->L;
      cur->R = new node(m + 1, sj, NULL, NULL);
      update(old->R, cur->R, i, j, bit);
    }
    cur->total = cur->L->total + cur->R->total;
  }
}
void update(node* old, node* cur, int i) {
  if (old->si == old->sj) {
    cur->B = old->B;
    for (int i = (0); i <= (M - 1); ++i) cur->B.flip(i);
    cur->total = cur->B.count();
  } else {
    int si = old->si;
    int sj = old->sj;
    int m = (si + sj) / 2;
    if (i <= m) {
      cur->R = old->R;
      cur->L = new node(si, m, NULL, NULL);
      update(old->L, cur->L, i);
    } else {
      cur->L = old->L;
      cur->R = new node(m + 1, sj, NULL, NULL);
      update(old->R, cur->R, i);
    }
    cur->total = cur->L->total + cur->R->total;
  }
}
int main() {
  int Q, x, y;
  cin >> N >> M >> Q;
  tree[0] = build(1, N);
  for (int i = 1; i <= Q; ++i) {
    int c;
    cin >> c;
    if (c == 1 or c == 2) {
      cin >> x >> y;
      tree[i] = new node(1, N, NULL, NULL);
      update(tree[i - 1], tree[i], x, y, 2 - c);
    }
    if (c == 3) {
      cin >> x;
      tree[i] = new node(1, N, NULL, NULL);
      update(tree[i - 1], tree[i], x);
    }
    if (c == 4) {
      cin >> x;
      tree[i] = tree[x];
    }
    cout << tree[i]->total << endl;
  }
}
