//longlong5a6
#include <bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define bit(i, x)((x >> i) & 1)
#define sobit(i) __builtin_popcount((int)(i))
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define For(i,x,n) for(int (i)=(int)(x);(i)<=(int)(n);(i)++)
#define round(m,n) setprecision((int)m) << fixed << double(n)
#define down "\n"
#define TASK "biendoi"
#define maxn 1001
using namespace std;
bool f[maxn][maxn];
bool g[maxn];
int c[maxn];
struct query
{
int ty,x,y;
}Q[maxn*100];
vector<query> his;
vector<int>line[maxn*100];
int n,m,q;
int cnt=0;
int res[maxn*100];
void up(int i)
{
if (Q[i].ty==1)
{
int x=Q[i].x;
int y=Q[i].y;
if(f[x][y]^g[x]==0)
{
c[x]++;
f[x][y]^=1;
cnt++;
his.pb(Q[i]);
}
else his.pb({4,0,0});
}
if (Q[i].ty==2)
{
int x=Q[i].x;
int y=Q[i].y;
if(f[x][y]^g[x]==1)
{
c[x]--;
f[x][y]^=1;
cnt--;
his.pb(Q[i]);
}
else his.pb({4,0,0});
}
if (Q[i].ty==3)
{
int x=Q[i].x;
cnt+=(m-c[x])-c[x];
c[x]=m-c[x];
g[x]^=1;
his.pb(Q[i]);
}
}
void Back(query a)
{
auto [ty,x,y]=a;
if (ty==1)
{
cnt--;
c[x]--;
f[x][y]^=1;
}
if (ty==2)
{
cnt++;
c[x]++;
f[x][y]^=1;
}
if (ty==3)
{
cnt+=(m-c[x])-c[x];
c[x]=m-c[x];
g[x]^=1;
}
}
void roll(int pos)
{
while ((int) his.size()>pos)
{
Back(his.back());
his.pop_back();
}
}
void dfs(int u)
{
up(u);
res[u]=cnt;
int pos=his.size();
for(auto i:line[u])
{
dfs(i);
roll(pos);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
if (fopen("in.txt","r"))
{
freopen("in.txt","r",stdin);
}
if (fopen(TASK".INP","r"))
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
cin>>n>>m>>q;
For(i,1,q)
{
int ty;
cin>>ty;
int x,y;
if (ty!=3&&ty!=4)
{
cin>>x>>y;
Q[i]={ty,x,y};
line[i-1].pb(i);
}
else
{
cin>>x;
Q[i]={ty,x,0};
if (ty==4) line[x].pb(i);
else line[i-1].pb(i);
}
}
dfs(0);
For(i,1,q) cout<<res[i]<<down;
}
Ly9sb25nbG9uZzVhNgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBwaWkgcGFpcjxpbnQsaW50PgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGJpdChpLCB4KSgoeCA+PiBpKSAmIDEpCiNkZWZpbmUgc29iaXQoaSkgIF9fYnVpbHRpbl9wb3Bjb3VudCgoaW50KShpKSkKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBhbGwoeCkgeC5iZWdpbigpLHguZW5kKCkKI2RlZmluZSB2aSB2ZWN0b3I8aW50PgojZGVmaW5lIEZvcihpLHgsbikgZm9yKGludCAoaSk9KGludCkoeCk7KGkpPD0oaW50KShuKTsoaSkrKykKI2RlZmluZSByb3VuZChtLG4pIHNldHByZWNpc2lvbigoaW50KW0pIDw8IGZpeGVkIDw8IGRvdWJsZShuKQojZGVmaW5lIGRvd24gIlxuIgojZGVmaW5lIFRBU0sgImJpZW5kb2kiCiNkZWZpbmUgbWF4biAxMDAxCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBmW21heG5dW21heG5dOwpib29sIGdbbWF4bl07CmludCBjW21heG5dOwoKc3RydWN0IHF1ZXJ5CnsKICAgIGludCB0eSx4LHk7Cn1RW21heG4qMTAwXTsKCnZlY3RvcjxxdWVyeT4gaGlzOwp2ZWN0b3I8aW50PmxpbmVbbWF4bioxMDBdOwppbnQgbixtLHE7CmludCBjbnQ9MDsKaW50IHJlc1ttYXhuKjEwMF07CnZvaWQgdXAoaW50IGkpCnsKICAgIGlmIChRW2ldLnR5PT0xKQogICAgewogICAgICAgIGludCB4PVFbaV0ueDsKICAgICAgICBpbnQgeT1RW2ldLnk7CiAgICAgICAgaWYoZlt4XVt5XV5nW3hdPT0wKQogICAgICAgIHsKICAgICAgICAgICAgY1t4XSsrOwogICAgICAgICAgICBmW3hdW3ldXj0xOwogICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgaGlzLnBiKFFbaV0pOwogICAgICAgIH0KICAgICAgICBlbHNlIGhpcy5wYih7NCwwLDB9KTsKICAgIH0KICAgIGlmIChRW2ldLnR5PT0yKQogICAgewogICAgICAgIGludCB4PVFbaV0ueDsKICAgICAgICBpbnQgeT1RW2ldLnk7CiAgICAgICAgaWYoZlt4XVt5XV5nW3hdPT0xKQogICAgICAgIHsKICAgICAgICAgICAgY1t4XS0tOwogICAgICAgICAgICBmW3hdW3ldXj0xOwogICAgICAgICAgICBjbnQtLTsKICAgICAgICAgICAgaGlzLnBiKFFbaV0pOwogICAgICAgIH0KICAgICAgICBlbHNlIGhpcy5wYih7NCwwLDB9KTsKICAgIH0KICAgIGlmIChRW2ldLnR5PT0zKQogICAgewogICAgICAgIGludCB4PVFbaV0ueDsKICAgICAgICBjbnQrPShtLWNbeF0pLWNbeF07CiAgICAgICAgY1t4XT1tLWNbeF07CiAgICAgICAgZ1t4XV49MTsKICAgICAgICBoaXMucGIoUVtpXSk7CiAgICB9Cn0Kdm9pZCBCYWNrKHF1ZXJ5IGEpCnsKICAgIGF1dG8gW3R5LHgseV09YTsKICAgIGlmICh0eT09MSkKICAgIHsKICAgICAgICBjbnQtLTsKICAgICAgICBjW3hdLS07CiAgICAgICAgZlt4XVt5XV49MTsKICAgIH0KICAgIGlmICh0eT09MikKICAgIHsKICAgICAgICBjbnQrKzsKICAgICAgICBjW3hdKys7CiAgICAgICAgZlt4XVt5XV49MTsKICAgIH0KICAgIGlmICh0eT09MykKICAgIHsKICAgICAgICBjbnQrPShtLWNbeF0pLWNbeF07CiAgICAgICAgY1t4XT1tLWNbeF07CiAgICAgICAgZ1t4XV49MTsKICAgIH0KfQp2b2lkIHJvbGwoaW50IHBvcykKewogICAgd2hpbGUgKChpbnQpIGhpcy5zaXplKCk+cG9zKQogICAgewogICAgICAgIEJhY2soaGlzLmJhY2soKSk7CiAgICAgICAgaGlzLnBvcF9iYWNrKCk7CiAgICB9Cn0Kdm9pZCBkZnMoaW50IHUpCnsKICAgIHVwKHUpOwogICAgcmVzW3VdPWNudDsKICAgIGludCBwb3M9aGlzLnNpemUoKTsKICAgIGZvcihhdXRvIGk6bGluZVt1XSkKICAgIHsKICAgICAgICBkZnMoaSk7CiAgICAgICAgcm9sbChwb3MpOwogICAgfQp9CgoKaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgICAgIGNpbi50aWUoKTsKICAgICAgICBjb3V0LnRpZSgpOwogICAgaWYgKGZvcGVuKCJpbi50eHQiLCJyIikpCiAgICAgICAgewogICAgICAgICAgICBmcmVvcGVuKCJpbi50eHQiLCJyIixzdGRpbik7CgogICAgICAgIH0KICAgIGlmIChmb3BlbihUQVNLIi5JTlAiLCJyIikpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZyZW9wZW4oVEFTSyIuSU5QIiwiciIsc3RkaW4pOwogICAgICAgICAgICAgICAgZnJlb3BlbihUQVNLIi5PVVQiLCJ3IixzdGRvdXQpOwogICAgICAgICAgICB9CiAgICBjaW4+Pm4+Pm0+PnE7CiAgICBGb3IoaSwxLHEpCiAgICB7CiAgICAgICAgaW50IHR5OwogICAgICAgIGNpbj4+dHk7CiAgICAgICAgaW50IHgseTsKICAgICAgICBpZiAodHkhPTMmJnR5IT00KQogICAgICAgIHsKICAgICAgICAgICAgY2luPj54Pj55OwogICAgICAgICAgICBRW2ldPXt0eSx4LHl9OwogICAgICAgICAgICBsaW5lW2ktMV0ucGIoaSk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGNpbj4+eDsKICAgICAgICAgICAgUVtpXT17dHkseCwwfTsKICAgICAgICAgICAgaWYgKHR5PT00KSBsaW5lW3hdLnBiKGkpOwogICAgICAgICAgICBlbHNlIGxpbmVbaS0xXS5wYihpKTsKICAgICAgICB9CiAgICB9ICAgCiAgICBkZnMoMCk7CiAgICBGb3IoaSwxLHEpIGNvdXQ8PHJlc1tpXTw8ZG93bjsKfQo=