#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int Q = 1e5 + 5;
int row[N];
int shelfs[N][N];
bool is_inverted[N];
int n, m, q;
vector<int> four[Q];
int qt[Q], ii[Q], jj[Q];
int ans[Q];
void solve(int i = 0, int books = 0) {
  if (int(four[i].size())) {
    for (int r = 0; r < int(int(four[i].size())); r++) {
      ans[four[i][r] - 1] = books;
      solve(four[i][r], books);
    }
  }
  if (qt[i] == 1) {
    if (!shelfs[ii[i]][jj[i]] && !is_inverted[ii[i]]) {
      shelfs[ii[i]][jj[i]] = 1;
      row[ii[i]]++;
      books++;
      ans[i] = books;
      solve(i + 1, books);
      shelfs[ii[i]][jj[i]] = 0;
      row[ii[i]]--;
      books--;
    } else if (shelfs[ii[i]][jj[i]] && is_inverted[ii[i]]) {
      shelfs[ii[i]][jj[i]] = 0;
      row[ii[i]]++;
      books++;
      ans[i] = books;
      solve(i + 1, books);
      shelfs[ii[i]][jj[i]] = 1;
      row[ii[i]]--;
      books--;
    } else {
      ans[i] = books;
      solve(i + 1, books);
    }
  } else if (qt[i] == 2) {
    if (shelfs[ii[i]][jj[i]] && !is_inverted[ii[i]]) {
      shelfs[ii[i]][jj[i]] = 0;
      row[ii[i]]--;
      books--;
      ans[i] = books;
      solve(i + 1, books);
      shelfs[ii[i]][jj[i]] = 1;
      row[ii[i]]++;
      books++;
    } else if (!shelfs[ii[i]][jj[i]] && is_inverted[ii[i]]) {
      shelfs[ii[i]][jj[i]] = 1;
      row[ii[i]]--;
      books--;
      ans[i] = books;
      solve(i + 1, books);
      shelfs[ii[i]][jj[i]] = 0;
      row[ii[i]]++;
      books++;
    } else {
      ans[i] = books;
      solve(i + 1, books);
    }
  } else if (qt[i] == 3) {
    is_inverted[ii[i]] = !is_inverted[ii[i]];
    books -= row[ii[i]];
    books += m - row[ii[i]];
    row[ii[i]] = m - row[ii[i]];
    ans[i] = books;
    solve(i + 1, books);
    is_inverted[ii[i]] = !is_inverted[ii[i]];
    row[ii[i]] = m - row[ii[i]];
    books -= m - row[ii[i]];
    books += row[ii[i]];
  } else {
    return;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < int(q); i++) {
    scanf("%d", &qt[i]);
    if (qt[i] == 1)
      scanf("%d%d", &ii[i], &jj[i]);
    else if (qt[i] == 2)
      scanf("%d%d", &ii[i], &jj[i]);
    else if (qt[i] == 3)
      scanf("%d", &ii[i]);
    else {
      scanf("%d", &ii[i]);
      four[ii[i]].push_back(i + 1);
    }
  }
  solve();
  for (int i = 0; i < int(q); i++) printf("%d\n", ans[i]);
  return 0;
}
