#include <bits/stdc++.h>
using namespace std;
bool mat[1222][1222];
vector<int> v[112233];
int row[100005];
int col[100005];
int type[100005];
int cnt = 0;
int ans[100005];
int n, m, q;
void dfs(int idx) {
  int visited = 0;
  if (type[idx] == 1) {
    if (mat[row[idx]][col[idx]] == false) {
      cnt++;
      visited = 1;
      mat[row[idx]][col[idx]] = true;
    }
  } else if (type[idx] == 2) {
    if (mat[row[idx]][col[idx]] == true) {
      cnt--;
      visited = 1;
      mat[row[idx]][col[idx]] = false;
    }
  } else if (type[idx] == 3) {
    visited = 1;
    for (int i = 1; i <= m; i++) {
      if (mat[row[idx]][i] == false) {
        cnt++;
        mat[row[idx]][i] = true;
      } else if (mat[row[idx]][i] == true) {
        cnt--;
        mat[row[idx]][i] = false;
      }
    }
  }
  ans[idx] = cnt;
  for (auto it : v[idx]) {
    dfs(it);
  }
  if (visited) {
    if (type[idx] == 1) {
      cnt--;
      mat[row[idx]][col[idx]] = false;
    } else if (type[idx] == 2) {
      cnt++;
      mat[row[idx]][col[idx]] = true;
    } else if (type[idx] == 3) {
      for (int i = 1; i <= m; i++) {
        if (mat[row[idx]][i] == false) {
          cnt++;
          mat[row[idx]][i] = true;
        } else {
          cnt--;
          mat[row[idx]][i] = false;
        }
      }
    }
  }
}
int main() {
  int i, j, k, l;
  int a, b, c;
  scanf("%d%d%d", &n, &m, &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 1 || type[i] == 2) {
      scanf("%d%d", &row[i], &col[i]);
      v[i - 1].push_back(i);
    } else if (type[i] == 3) {
      scanf("%d", &row[i]);
      v[i - 1].push_back(i);
    } else {
      scanf("%d", &b);
      v[b].push_back(i);
    }
  }
  dfs(0);
  for (i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
