using namespace std;
#include <bits/stdc++.h>
#define fori(a, b) for(int i = a;i <= b;i++)
#define forj(a, b) for(int j = a;j <= b;j++)
#define forl(a, b) for(int l = a;l <= b;l++)
#define fordi(b, a) for(int i = b;i >= a;i--)
#define fordj(b, a) for(int j = b;j >= a;j--)
#define fordl(b, a) for(int l = b;l >= a;l--)
#define MAX 100100
#define MAGIC 29
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1);
typedef long long ll;
int n, m, q, res[MAX], cont, acm[MAX];
vector<int> adj[MAX];
pair<int, int> rm[MAX];
pair<int, int> add[MAX];
int swp[MAX];
bool shelf[1010][1010];
bool rev[1010];
bool fadd(int a, int b){
if(!rev[a]){
if(shelf[a][b]) return false;
else{
cont++;
acm[a]++;
return shelf[a][b] = true;
}
}
else{
if(shelf[a][b]){
cont++;
acm[a]++;
shelf[a][b] = false;
return true;
}
else return false;
}
}
bool frm(int a, int b){
//cout << "rm " << a << " " << b << " " << rev[a] << endl;
if(!rev[a]){
if(shelf[a][b]){
cont--;
acm[a]--;
shelf[a][b] = false;
return true;
}
else return false;
}
else{
if(shelf[a][b]) return false;
else{
cont--;
acm[a]--;
shelf[a][b] = true;
return true;
}
}
}
bool frv(int a){
cont += m - 2*acm[a];
acm[a] = m - acm[a];
rev[a] = !rev[a];
return true;
}
void f(int pos){
bool done = false;
if(add[pos].F != -1) done = fadd(add[pos].F, add[pos].S);
if(rm[pos].F != -1) done = frm(rm[pos].F, rm[pos].S);
if(swp[pos] != -1) done = frv(swp[pos]);
//cout << "f " << pos << " " << done << endl;
res[pos] = cont;
fori(0, (int)adj[pos].size() - 1) f(adj[pos][i]);
if(done){
if(add[pos].F != -1) frm(add[pos].F, add[pos].S);
if(rm[pos].F != -1) fadd(rm[pos].F, rm[pos].S);
if(swp[pos] != -1) frv(swp[pos]);
}
}
int main(){
//freopen("in", "r", stdin);
int a, b, c;
memset(shelf, false, sizeof(shelf));
memset(rev, false, sizeof(rev));
memset(acm, 0, sizeof(acm));
cont = 0;
add[0] = mp(-1, -1);
rm[0] = mp(-1, -1);
swp[0] = -1;
cin >> n >> m >> q;
fori(1, q){
scanf("%d", &a);
if(a == 1 || a == 2){
scanf("%d %d", &b, &c);
}
else scanf("%d", &b);
add[i] = mp(-1, -1);
rm[i] = mp(-1, -1);
swp[i] = -1;
if(a == 1) add[i] = mp(b, c);
else if(a == 2) rm[i] = mp(b, c);
else if(a == 3) swp[i] = b;
else adj[b].pb(i);
if(a != 4) adj[i-1].pb(i);
}
f(0);
fori(1, q) printf("%d\n", res[i]);
return 0;
}
dXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGZvcmkoYSwgYikgZm9yKGludCBpID0gYTtpIDw9IGI7aSsrKQojZGVmaW5lIGZvcmooYSwgYikgZm9yKGludCBqID0gYTtqIDw9IGI7aisrKQojZGVmaW5lIGZvcmwoYSwgYikgZm9yKGludCBsID0gYTtsIDw9IGI7bCsrKQojZGVmaW5lIGZvcmRpKGIsIGEpIGZvcihpbnQgaSA9IGI7aSA+PSBhO2ktLSkKI2RlZmluZSBmb3JkaihiLCBhKSBmb3IoaW50IGogPSBiO2ogPj0gYTtqLS0pCiNkZWZpbmUgZm9yZGwoYiwgYSkgZm9yKGludCBsID0gYjtsID49IGE7bC0tKQoKI2RlZmluZSBNQVggMTAwMTAwCiNkZWZpbmUgTUFHSUMgMjkKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgoKY29uc3QgZG91YmxlIFBJID0gYWNvcygtMSk7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKaW50IG4sIG0sIHEsIHJlc1tNQVhdLCBjb250LCBhY21bTUFYXTsKdmVjdG9yPGludD4gYWRqW01BWF07CnBhaXI8aW50LCBpbnQ+IHJtW01BWF07CnBhaXI8aW50LCBpbnQ+IGFkZFtNQVhdOwppbnQgc3dwW01BWF07CmJvb2wgc2hlbGZbMTAxMF1bMTAxMF07CmJvb2wgcmV2WzEwMTBdOwoKYm9vbCBmYWRkKGludCBhLCBpbnQgYil7CgogICAgaWYoIXJldlthXSl7CiAgICAgICAgaWYoc2hlbGZbYV1bYl0pIHJldHVybiBmYWxzZTsKICAgICAgICBlbHNlewogICAgICAgICAgICBjb250Kys7CiAgICAgICAgICAgIGFjbVthXSsrOwogICAgICAgICAgICByZXR1cm4gc2hlbGZbYV1bYl0gPSB0cnVlOwogICAgICAgIH0KICAgIH0KICAgIGVsc2V7CiAgICAgICAgaWYoc2hlbGZbYV1bYl0pewogICAgICAgICAgICBjb250Kys7CiAgICAgICAgICAgIGFjbVthXSsrOwogICAgICAgICAgICBzaGVsZlthXVtiXSA9IGZhbHNlOwogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgZWxzZSByZXR1cm4gZmFsc2U7CiAgICB9Cn0KCmJvb2wgZnJtKGludCBhLCBpbnQgYil7CgogICAgLy9jb3V0IDw8ICJybSAiIDw8IGEgPDwgIiAiIDw8IGIgPDwgIiAiIDw8IHJldlthXSA8PCBlbmRsOwogICAgCiAgICBpZighcmV2W2FdKXsKICAgICAgICBpZihzaGVsZlthXVtiXSl7CiAgICAgICAgICAgIGNvbnQtLTsKICAgICAgICAgICAgYWNtW2FdLS07CiAgICAgICAgICAgIHNoZWxmW2FdW2JdID0gZmFsc2U7CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICBlbHNlIHJldHVybiBmYWxzZTsKICAgIH0KICAgIGVsc2V7CiAgICAgICAgaWYoc2hlbGZbYV1bYl0pIHJldHVybiBmYWxzZTsKICAgICAgICBlbHNlewogICAgICAgICAgICBjb250LS07CiAgICAgICAgICAgIGFjbVthXS0tOwogICAgICAgICAgICBzaGVsZlthXVtiXSA9IHR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