#include <bits/stdc++.h>
using namespace std;
const int mm = 1001;
struct box {
  vector<shared_ptr<bitset<mm>>> v;
  int sum;
};
struct per_box {
  per_box *p = nullptr;
  int sum = 0;
  map<int, shared_ptr<bitset<mm>>> shelf;
  per_box() = default;
  per_box &operator=(per_box &rhs) {
    p = &rhs;
    sum = p->sum;
    return *this;
  }
  int test(int i, int j) {
    if (shelf.find(i) != shelf.end()) {
      return shelf[i]->test(j);
    }
    return p->test(i, j);
  }
  shared_ptr<bitset<mm>> find(int i) {
    if (shelf.find(i) != shelf.end()) {
      return shelf[i];
    }
    if (p == nullptr) return nullptr;
    return p->find(i);
  }
  int set(int i, int j, bool value) {
    auto bs = find(i);
    if (bs != nullptr)
      shelf[i] = shared_ptr<bitset<mm>>(new bitset<mm>(*bs));
    else
      shelf[i] = shared_ptr<bitset<mm>>(new bitset<mm>(0));
    int c1 = shelf[i]->test(j);
    shelf[i]->set(j, value);
    int c = value ? c1 ^ 1 : -c1;
    sum += c;
    return c;
  }
  int flip(int i, const bitset<mm> &mask) {
    auto bs = find(i);
    if (bs != nullptr)
      shelf[i] = shared_ptr<bitset<mm>>(new bitset<mm>(*bs));
    else
      shelf[i] = shared_ptr<bitset<mm>>(new bitset<mm>(0));
    int c = -shelf[i]->count();
    shelf[i]->flip();
    (*shelf[i]) &= mask;
    c += shelf[i]->count();
    sum += c;
    return c;
  }
};
int inf = numeric_limits<int>::max();
int main() {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  bitset<mm> mask(0);
  for (int i = 0; i < m; i++) mask.set(i);
  vector<per_box> per_ward(q + 1);
  vector<tuple<int, int, int>> qu(q);
  for (int i = 0; i < q; i++) {
    int op;
    cin >> op;
    if (op == 1 || op == 2) {
      int op1, op2;
      cin >> op1 >> op2;
      qu[i] = make_tuple(op, op1 - 1, op2 - 1);
    } else {
      int op1;
      cin >> op1;
      qu[i] = make_tuple(op, op1 - 1, -1);
    }
  }
  for (int it = 0; it < qu.size(); it++) {
    int op = get<0>(qu[it]);
    int w = it + 1;
    if (op == 1) {
      int i = get<1>(qu[it]), j = get<2>(qu[it]);
      per_ward[w] = per_ward[w - 1];
      per_ward[w].set(i, j, true);
    } else if (op == 2) {
      int i = get<1>(qu[it]), j = get<2>(qu[it]);
      per_ward[w] = per_ward[w - 1];
      per_ward[w].set(i, j, false);
    } else if (op == 3) {
      int i = get<1>(qu[it]);
      per_ward[w] = per_ward[w - 1];
      per_ward[w].flip(i, mask);
    } else if (op == 4) {
      int k = get<1>(qu[it]) + 1;
      per_ward[w] = per_ward[k];
    }
    std::cout << per_ward[w].sum << "\n";
  }
}
