#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,m,q;
vector<int> E[maxn];
int op[maxn],a[maxn],b[maxn];
int ans[maxn];
bitset<1001>Bit[1001];
bitset<1001>C;
void dfs(int x)
{
    if(x==0)
    {
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
    if(op[x]==1)
    {
        int flag = 0;
        if(!Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]++;
            Bit[a[x]][b[x]]=1;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=0;
    }
    if(op[x]==2)
    {
        int flag = 0;
        if(Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]--;
            Bit[a[x]][b[x]]=0;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=1;
    }
    if(op[x]==3)
    {
        ans[x]=ans[x]-Bit[a[x]].count();
        Bit[a[x]]^=C;
        ans[x]=ans[x]+Bit[a[x]].count();
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        Bit[a[x]]^=C;
    }
    if(op[x]==4)
    {
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=m;i++)
        C[i]=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&op[i]);
        if(op[i]==1)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==2)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==3)
            scanf("%d",&a[i]);
        if(op[i]==4)
            scanf("%d",&a[i]),
            E[a[i]].push_back(i);
        else
            E[i-1].push_back(i);
    }
    dfs(0);
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,m,q;
vector<int> E[maxn];
int op[maxn],a[maxn],b[maxn],c[maxn];
int ans[maxn];
bitset<1001>Bit[1001];
bitset<1001>C;
void dfs(int x)
{
    if(op[x]==1)
    {
        int flag = 0;
        if(!Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]++;
            Bit[a[x]][b[x]]=1;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=0;
    }
    if(op[x]==2)
    {
        int flag = 0;
        if(Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]--;
            Bit[a[x]][b[x]]=0;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=1;
    }
    if(op[x]==3)
    {
        ans[x]=ans[x]-Bit[a[x]].count();
        Bit[a[x]]^=C;
        ans[x]=ans[x]+Bit[a[x]].count();
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        Bit[a[x]]^=C;
    }
    if(op[x]==4)
    {
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=m;i++)
        C[i]=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&op[i]);
        if(op[i]==1)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==2)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==3)
            scanf("%d",&a[i]);
        if(op[i]==4)
            scanf("%d",&a[i]),
            E[a[i]].push_back(i);
        else
            E[i-1].push_back(i);
    }
    for(int i=0;i<E[0].size();i++)
    {
        ans[E[0][i]]=ans[0];
        dfs(E[0][i]);
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e3+3;
const int maxn=1e5+3;
int n,m,q;
vector<int> G[N];
bitset<N> bit[N];
bitset<N> opp;
int ope[maxn],a[maxn],b[maxn],ans[maxn];
void dfs(int x)
{
    if(ope[x]==1)
    {
        int flag=0;
        if(!bit[a[x]][b[x]])
        {
            bit[a[x]][b[x]]=1;
            ans[x]++;
            flag=1;
        }
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
        if(flag)
            bit[a[x]][b[x]]=0;

    }
    else if(ope[x]==2)
    {
        int flag=0;
        if(bit[a[x]][b[x]])
        {
            bit[a[x]][b[x]]=0;
            ans[x]--;
            flag=1;
        }
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
        if(flag)
            bit[a[x]][b[x]]=1;
    }
    else if(ope[x]==3)
    {
        ans[x]+=m-2*bit[a[x]].count();
        bit[a[x]]^=opp;
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
        bit[a[x]]^=opp;
    }
    else
    {
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
    }
}
int main()
{
    scanf("%d %d %d",&n,&m,&q);
    for(int i=1;i<=m;i++)
        opp[i]=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&ope[i]);
        if(ope[i]==1)
        {
            scanf("%d %d",a+i,b+i);
            G[i-1].push_back(i);
        }
        else if(ope[i]==2)
        {
            scanf("%d %d",a+i,b+i);
            G[i-1].push_back(i);
        }
        else if(ope[i]==3)
        {
            scanf("%d",a+i);
            G[i-1].push_back(i);
        }
        else
        {
            scanf("%d",a+i);
            G[a[i]].push_back(i);
        }
    }
    for(int i=0;i<G[0].size();i++)
    {
        ans[G[0][i]]=0;
        dfs(G[0][i]);
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,m,q;
vector<int> E[maxn];
int op[maxn],a[maxn],b[maxn],c[maxn];
int ans[maxn];
bitset<1001>Bit[1001];
bitset<1001>C;
void dfs(int x)
{
    if(x==0)
    {
        for(int i=0;i<1;i++)
        {
            ans[E[0][i]]=0;
            dfs(E[0][i]);
        }
    }
    if(op[x]==1)
    {
        int flag = 0;
        if(!Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]++;
            Bit[a[x]][b[x]]=1;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=0;
    }
    if(op[x]==2)
    {
        int flag = 0;
        if(Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]--;
            Bit[a[x]][b[x]]=0;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=1;
    }
    if(op[x]==3)
    {
        ans[x]=ans[x]-Bit[a[x]].count();
        Bit[a[x]]^=C;
        ans[x]=ans[x]+Bit[a[x]].count();
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        Bit[a[x]]^=C;
    }
    if(op[x]==4)
    {
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=m;i++)
        C[i]=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&op[i]);
        if(op[i]==1)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==2)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==3)
            scanf("%d",&a[i]);
        if(op[i]==4)
            scanf("%d",&a[i]),
            E[a[i]].push_back(i);
        else
            E[i-1].push_back(i);
    }
    dfs(0);
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5;
int num[N],ans[N];
int main()
{
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;i++)
    {
        int c;
        scanf("%d",&c);
        if(c==1)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            ans[i]=ans[i-1]+1;
            num[x]++;
            printf("%d\n",ans[i]);
        }
        if(c==2)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            ans[i]=ans[i-1]-1;
            num[x]--;
            printf("%d\n",ans[i]);
        }
        if(c==3)
        {
            int x;
            scanf("%d",&x);
            ans[i]=ans[i-1]+m-2*num[x];
            num[x]=m-num[x];
            printf("%d\n",ans[i]);
        }
        if(c==4)
        {
            int x;
            ans[i]=ans[x];
            printf("%d\n",ans[x]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e3+3;
const int maxn=1e5+3;
int n,m,q;
vector<int> G[maxn];
bitset<N> bit[N];
bitset<N> opp;
int ope[maxn],a[maxn],b[maxn],ans[maxn];
void dfs(int x)
{
    if(ope[x]==1)
    {
        int flag=0;
        if(!bit[a[x]][b[x]])
        {
            bit[a[x]][b[x]]=1;
            ans[x]++;
            flag=1;
        }
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
        if(flag)
            bit[a[x]][b[x]]=0;

    }
    else if(ope[x]==2)
    {
        int flag=0;
        if(bit[a[x]][b[x]])
        {
            bit[a[x]][b[x]]=0;
            ans[x]--;
            flag=1;
        }
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
        if(flag)
            bit[a[x]][b[x]]=1;
    }
    else if(ope[x]==3)
    {
        ans[x]+=m-2*bit[a[x]].count();
        bit[a[x]]^=opp;
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
        bit[a[x]]^=opp;
    }
    else
    {
        for(int i=0;i<G[x].size();i++)
        {
            ans[G[x][i]]=ans[x];
            dfs(G[x][i]);
        }
    }
}
int main()
{
    scanf("%d %d %d",&n,&m,&q);
    for(int i=1;i<=m;i++)
        opp[i]=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&ope[i]);
        if(ope[i]==1)
        {
            scanf("%d %d",a+i,b+i);
            G[i-1].push_back(i);
        }
        else if(ope[i]==2)
        {
            scanf("%d %d",a+i,b+i);
            G[i-1].push_back(i);
        }
        else if(ope[i]==3)
        {
            scanf("%d",a+i);
            G[i-1].push_back(i);
        }
        else
        {
            scanf("%d",a+i);
            G[a[i]].push_back(i);
        }
    }
    for(int i=0;i<G[0].size();i++)
    {
        ans[G[0][i]]=0;
        dfs(G[0][i]);
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,m,q;
vector<int> E[maxn];
int op[maxn],a[maxn],b[maxn],c[maxn];
int ans[maxn];
bitset<1001> Bit[1001];
bitset<1001> C;
void dfs(int x)
{
    if(op[x]==1)
    {
        int flag = 0;
        if(!Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]++;
            Bit[a[x]][b[x]]=1;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=0;
    }
    if(op[x]==2)
    {
        int flag = 0;
        if(Bit[a[x]][b[x]])
        {
            flag = 1;
            ans[x]--;
            Bit[a[x]][b[x]]=0;
        }
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(flag)
            Bit[a[x]][b[x]]=1;
    }
    if(op[x]==3)
    {
        ans[x]=ans[x]-Bit[a[x]].count();
        Bit[a[x]].flip();
        ans[x]=ans[x]+Bit[a[x]].count();
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        Bit[a[x]].flip();
    }
    if(op[x]==4)
    {
        for(int i=0;i<E[x].size();i++)
        {
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=m;i++)
        C[i]=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&op[i]);
        if(op[i]==1)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==2)
            scanf("%d%d",&a[i],&b[i]);
        if(op[i]==3)
            scanf("%d",&a[i]);
        if(op[i]==4)
            scanf("%d",&a[i]),
            E[a[i]].push_back(i);
        else
            E[i-1].push_back(i);
    }
    for(int i=0;i<E[0].size();i++)
    {
        ans[E[0][i]]=ans[0];
        dfs(E[0][i]);
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int root[100100],tot;
struct node
{
    int lch,rch,rev,sum1,sum0;
}seg[5000100];
void upd(int n)
{
    int lch=seg[n].lch, rch=seg[n].rch;
    //printf("0.0 %d %d %d %d %d\n",n,lch,rch,seg[lch].sum1,seg[rch].sum1);
    seg[n].sum0=seg[lch].sum0+seg[rch].sum0;
    seg[n].sum1=seg[lch].sum1+seg[rch].sum1;
}
void build(int l,int r,int num)
{
	seg[num].rev=0;
    if(l==r)
    {
        seg[num].sum0=1; seg[num].sum1=0;
        return;
    }
    int mid=(l+r)>>1;
    seg[num].lch=++tot;
    build(l,mid,tot);
    seg[num].rch=++tot;
    build(mid+1,r,tot);
    upd(num);
}

void relax(int n,int now)
{

    int lch=seg[n].lch, rch=seg[n].rch,l=seg[now].lch,r=seg[now].rch;
    //	printf("==%d	%d	%d %d %d	%d? %d\n",now,n,lch,l,r,rch,seg[n].rev);
		//���´������Ƹ���
    if(seg[now].rev==0){
		seg[l].sum0=seg[lch].sum0;
		seg[l].sum1=seg[lch].sum1;
		seg[r].sum0=seg[rch].sum0;
		seg[r].sum1=seg[rch].sum1;
		seg[l].rev=seg[lch].rev;
		seg[r].rev=seg[rch].rev;
    	return;
	}
	//�´���ˢ��
    seg[l].rev=seg[lch].rev^1;
    seg[r].rev=seg[rch].rev^1;
    seg[now].rev=0;
    seg[l].sum0=seg[lch].sum1;
    seg[l].sum1=seg[lch].sum0;
    seg[r].sum0=seg[rch].sum1;
    seg[r].sum1=seg[rch].sum0;
//	printf("+ %d	%d\n",seg[lch].sum0,seg[rch].sum0);
}

void update(int l,int r,int pos,int pre,int now,int a,int b)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(l==r&&l==pos)
    {
    //	printf("..%d %d %d.\n",pre,now,pos);
        seg[now].sum0=a; seg[now].sum1=b;
        seg[now].rev=0;
        return;
    }
    if(l<=pos&&pos<=r)
    {
        seg[now].lch=++tot;
		seg[now].rch=++tot;
        relax(pre,now);
        update(l,m,pos,seg[pre].lch,seg[now].lch,a,b);
		update(m+1,r,pos,seg[pre].rch,seg[now].rch,a,b);
		upd(now);
    }
   // printf("%d  %d  %d  %d  %d\n",l,r,pos,now,pre);
}

void revers(int l,int r,int ll,int rr,int pre,int now)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(ll<=l&&r<=rr)
    {
        seg[now].rev^=1;
        //printf("--%d %d %d %d\n",ll,rr,now,seg[now].rev);
        seg[now].sum0=seg[pre].sum1;
        seg[now].sum1=seg[pre].sum0;
        return;
    }
    if(l<=rr&&ll<=r)
    {
        seg[now].lch=++tot;
        seg[now].rch=++tot;
        relax(pre,now);
        revers(l,m,ll,rr,seg[pre].lch,seg[now].lch);
        revers(m+1,r,ll,rr,seg[pre].rch,seg[now].rch);
		upd(now);
    }
    //printf("%d  %d  %d  %d  %d  %d\n",l,r,ll,rr,now,pre);
}

int main()
{
    int n,m,i,j,q,oper,k;
   // freopen("out.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&q);
    build(1,n*m,tot);
    for(k=1;k<=q;k++)
    {
        scanf("%d",&oper);
        switch(oper)
        {
            case 1: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],0,1);
                    break;
            case 2: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],1,0);
                    break;
            case 3: scanf("%d",&i);
                    root[k]=++tot;
                    revers(1,n*m,(i-1)*m+1,i*m,root[k-1],root[k]);
                    break;
            case 4: scanf("%d",&i);
                    root[k]=root[i];
        }
        printf("%d\n",seg[root[k]].sum1);
    }
    return 0;
}
/*
4 2 100
1 1 2
3 1
3 2
3 1
3 2
2 2 1
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int root[100100],tot;
struct node
{
    int lch,rch,rev,sum1,sum0;
}seg[7000100];
void upd(int n)
{
    int lch=seg[n].lch, rch=seg[n].rch;
    //printf("0.0 %d %d %d %d %d\n",n,lch,rch,seg[lch].sum1,seg[rch].sum1);
    seg[n].sum0=seg[lch].sum0+seg[rch].sum0;
    seg[n].sum1=seg[lch].sum1+seg[rch].sum1;
}
void build(int l,int r,int num)
{
	seg[num].rev=0;
    if(l==r)
    {
        seg[num].sum0=1; seg[num].sum1=0;
        return;
    }
    int mid=(l+r)>>1;
    seg[num].lch=++tot;
    build(l,mid,tot);
    seg[num].rch=++tot;
    build(mid+1,r,tot);
    upd(num);
}

void relax(int n,int now)
{

    int lch=seg[n].lch, rch=seg[n].rch,l=seg[now].lch,r=seg[now].rch;
    //	printf("==%d	%d	%d %d %d	%d? %d\n",now,n,lch,l,r,rch,seg[n].rev);
		//���´������Ƹ���
    if(seg[now].rev==0){
		seg[l].sum0=seg[lch].sum0;
		seg[l].sum1=seg[lch].sum1;
		seg[r].sum0=seg[rch].sum0;
		seg[r].sum1=seg[rch].sum1;
		seg[l].rev=seg[lch].rev;
		seg[r].rev=seg[rch].rev;
    	return;
	}
	//�´���ˢ��
    seg[l].rev=seg[lch].rev^1;
    seg[r].rev=seg[rch].rev^1;
    seg[now].rev=0;
    seg[l].sum0=seg[lch].sum1;
    seg[l].sum1=seg[lch].sum0;
    seg[r].sum0=seg[rch].sum1;
    seg[r].sum1=seg[rch].sum0;
//	printf("+ %d	%d\n",seg[lch].sum0,seg[rch].sum0);
}

void update(int l,int r,int pos,int pre,int now,int a,int b)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(l==r&&l==pos)
    {
    //	printf("..%d %d %d.\n",pre,now,pos);
        seg[now].sum0=a; seg[now].sum1=b;
        seg[now].rev=0;
        return;
    }
    if(l<=pos&&pos<=r)
    {
        seg[now].lch=++tot;
		seg[now].rch=++tot;
        relax(pre,now);
        update(l,m,pos,seg[pre].lch,seg[now].lch,a,b);
		update(m+1,r,pos,seg[pre].rch,seg[now].rch,a,b);
		upd(now);
    }
   // printf("%d  %d  %d  %d  %d\n",l,r,pos,now,pre);
}

void revers(int l,int r,int ll,int rr,int pre,int now)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(ll<=l&&r<=rr)
    {
        seg[now].rev^=1;
        //printf("--%d %d %d %d\n",ll,rr,now,seg[now].rev);
        seg[now].sum0=seg[pre].sum1;
        seg[now].sum1=seg[pre].sum0;
        return;
    }
    if(l<=rr&&ll<=r)
    {
        seg[now].lch=++tot;
        seg[now].rch=++tot;
        relax(pre,now);
        revers(l,m,ll,rr,seg[pre].lch,seg[now].lch);
        revers(m+1,r,ll,rr,seg[pre].rch,seg[now].rch);
		upd(now);
    }
    //printf("%d  %d  %d  %d  %d  %d\n",l,r,ll,rr,now,pre);
}

int main()
{
    int n,m,i,j,q,oper,k;
   // freopen("out.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&q);
    build(1,n*m,tot);
    for(k=1;k<=q;k++)
    {
        scanf("%d",&oper);
        switch(oper)
        {
            case 1: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],0,1);
                    break;
            case 2: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],1,0);
                    break;
            case 3: scanf("%d",&i);
                    root[k]=++tot;
                    revers(1,n*m,(i-1)*m+1,i*m,root[k-1],root[k]);
                    break;
            case 4: scanf("%d",&i);
                    root[k]=root[i];
        }
        printf("%d\n",seg[root[k]].sum1);
    }
    return 0;
}
/*
4 2 100
1 1 2
3 1
3 2
3 1
3 2
2 2 1
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int root[100100],tot;
struct node
{
    int lch,rch,rev,sum1,sum0;
}seg[10000100];
void upd(int n)
{
    int lch=seg[n].lch, rch=seg[n].rch;
    //printf("0.0 %d %d %d %d %d\n",n,lch,rch,seg[lch].sum1,seg[rch].sum1);
    seg[n].sum0=seg[lch].sum0+seg[rch].sum0;
    seg[n].sum1=seg[lch].sum1+seg[rch].sum1;
}
void build(int l,int r,int num)
{
	seg[num].rev=0;
    if(l==r)
    {
        seg[num].sum0=1; seg[num].sum1=0;
        return;
    }
    int mid=(l+r)>>1;
    seg[num].lch=++tot;
    build(l,mid,tot);
    seg[num].rch=++tot;
    build(mid+1,r,tot);
    upd(num);
}

void relax(int n,int now)
{

    int lch=seg[n].lch, rch=seg[n].rch,l=seg[now].lch,r=seg[now].rch;
    //	printf("==%d	%d	%d %d %d	%d? %d\n",now,n,lch,l,r,rch,seg[n].rev);
		//���´������Ƹ���
    if(seg[now].rev==0){
		seg[l].sum0=seg[lch].sum0;
		seg[l].sum1=seg[lch].sum1;
		seg[r].sum0=seg[rch].sum0;
		seg[r].sum1=seg[rch].sum1;
		seg[l].rev=seg[lch].rev;
		seg[r].rev=seg[rch].rev;
    	return;
	}
	//�´���ˢ��
    seg[l].rev=seg[lch].rev^1;
    seg[r].rev=seg[rch].rev^1;
    seg[now].rev=0;
    seg[l].sum0=seg[lch].sum1;
    seg[l].sum1=seg[lch].sum0;
    seg[r].sum0=seg[rch].sum1;
    seg[r].sum1=seg[rch].sum0;
//	printf("+ %d	%d\n",seg[lch].sum0,seg[rch].sum0);
}

void update(int l,int r,int pos,int pre,int now,int a,int b)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(l==r&&l==pos)
    {
    //	printf("..%d %d %d.\n",pre,now,pos);
        seg[now].sum0=a; seg[now].sum1=b;
        seg[now].rev=0;
        return;
    }
    if(l<=pos&&pos<=r)
    {
        seg[now].lch=++tot;
		seg[now].rch=++tot;
        relax(pre,now);
        update(l,m,pos,seg[pre].lch,seg[now].lch,a,b);
		update(m+1,r,pos,seg[pre].rch,seg[now].rch,a,b);
		upd(now);
    }
   // printf("%d  %d  %d  %d  %d\n",l,r,pos,now,pre);
}

void revers(int l,int r,int ll,int rr,int pre,int now)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(ll<=l&&r<=rr)
    {
        seg[now].rev^=1;
        //printf("--%d %d %d %d\n",ll,rr,now,seg[now].rev);
        seg[now].sum0=seg[pre].sum1;
        seg[now].sum1=seg[pre].sum0;
        return;
    }
    if(l<=rr&&ll<=r)
    {
        seg[now].lch=++tot;
        seg[now].rch=++tot;
        relax(pre,now);
        revers(l,m,ll,rr,seg[pre].lch,seg[now].lch);
        revers(m+1,r,ll,rr,seg[pre].rch,seg[now].rch);
		upd(now);
    }
    //printf("%d  %d  %d  %d  %d  %d\n",l,r,ll,rr,now,pre);
}

int main()
{
    int n,m,i,j,q,oper,k;
   // freopen("out.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&q);
    build(1,n*m,tot);
    for(k=1;k<=q;k++)
    {
        scanf("%d",&oper);
        switch(oper)
        {
            case 1: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],0,1);
                    break;
            case 2: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],1,0);
                    break;
            case 3: scanf("%d",&i);
                    root[k]=++tot;
                    revers(1,n*m,(i-1)*m+1,i*m,root[k-1],root[k]);
                    break;
            case 4: scanf("%d",&i);
                    root[k]=root[i];
        }
        printf("%d\n",seg[root[k]].sum1);
    }
    return 0;
}
/*
4 2 100
1 1 2
3 1
3 2
3 1
3 2
2 2 1
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int root[100100],tot;
struct node
{
    int lch,rch,rev,sum1,sum0;
}seg[8000100];
void upd(int n)
{
    int lch=seg[n].lch, rch=seg[n].rch;
    //printf("0.0 %d %d %d %d %d\n",n,lch,rch,seg[lch].sum1,seg[rch].sum1);
    seg[n].sum0=seg[lch].sum0+seg[rch].sum0;
    seg[n].sum1=seg[lch].sum1+seg[rch].sum1;
}
void build(int l,int r,int num)
{
	seg[num].rev=0;
    if(l==r)
    {
        seg[num].sum0=1; seg[num].sum1=0;
        return;
    }
    int mid=(l+r)>>1;
    seg[num].lch=++tot;
    build(l,mid,tot);
    seg[num].rch=++tot;
    build(mid+1,r,tot);
    upd(num);
}

void relax(int n,int now)
{

    int lch=seg[n].lch, rch=seg[n].rch,l=seg[now].lch,r=seg[now].rch;
    //	printf("==%d	%d	%d %d %d	%d? %d\n",now,n,lch,l,r,rch,seg[n].rev);
		//���´������Ƹ���
    if(seg[now].rev==0){
		seg[l].sum0=seg[lch].sum0;
		seg[l].sum1=seg[lch].sum1;
		seg[r].sum0=seg[rch].sum0;
		seg[r].sum1=seg[rch].sum1;
		seg[l].rev=seg[lch].rev;
		seg[r].rev=seg[rch].rev;
    	return;
	}
	//�´���ˢ��
    seg[l].rev=seg[lch].rev^1;
    seg[r].rev=seg[rch].rev^1;
    seg[now].rev=0;
    seg[l].sum0=seg[lch].sum1;
    seg[l].sum1=seg[lch].sum0;
    seg[r].sum0=seg[rch].sum1;
    seg[r].sum1=seg[rch].sum0;
//	printf("+ %d	%d\n",seg[lch].sum0,seg[rch].sum0);
}

void update(int l,int r,int pos,int pre,int now,int a,int b)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(l==r&&l==pos)
    {
    //	printf("..%d %d %d.\n",pre,now,pos);
        seg[now].sum0=a; seg[now].sum1=b;
        seg[now].rev=0;
        return;
    }
    if(l<=pos&&pos<=r)
    {
        seg[now].lch=++tot;
		seg[now].rch=++tot;
        relax(pre,now);
        update(l,m,pos,seg[pre].lch,seg[now].lch,a,b);
		update(m+1,r,pos,seg[pre].rch,seg[now].rch,a,b);
		upd(now);
    }
   // printf("%d  %d  %d  %d  %d\n",l,r,pos,now,pre);
}

void revers(int l,int r,int ll,int rr,int pre,int now)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(ll<=l&&r<=rr)
    {
        seg[now].rev^=1;
        //printf("--%d %d %d %d\n",ll,rr,now,seg[now].rev);
        seg[now].sum0=seg[pre].sum1;
        seg[now].sum1=seg[pre].sum0;
        return;
    }
    if(l<=rr&&ll<=r)
    {
        seg[now].lch=++tot;
        seg[now].rch=++tot;
        relax(pre,now);
        revers(l,m,ll,rr,seg[pre].lch,seg[now].lch);
        revers(m+1,r,ll,rr,seg[pre].rch,seg[now].rch);
		upd(now);
    }
    //printf("%d  %d  %d  %d  %d  %d\n",l,r,ll,rr,now,pre);
}

int main()
{
    int n,m,i,j,q,oper,k;
   // freopen("out.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&q);
    build(1,n*m,tot);
    for(k=1;k<=q;k++)
    {
        scanf("%d",&oper);
        switch(oper)
        {
            case 1: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],0,1);
                    break;
            case 2: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],1,0);
                    break;
            case 3: scanf("%d",&i);
                    root[k]=++tot;
                    revers(1,n*m,(i-1)*m+1,i*m,root[k-1],root[k]);
                    break;
            case 4: scanf("%d",&i);
                    root[k]=root[i];
        }
        printf("%d\n",seg[root[k]].sum1);
    }
    return 0;
}
/*
4 2 100
1 1 2
3 1
3 2
3 1
3 2
2 2 1
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int root[100100],tot;
struct node
{
    int lch,rch,rev,sum1,sum0;
}seg[50001000];
void upd(int n)
{
    int lch=seg[n].lch, rch=seg[n].rch;
    //printf("0.0 %d %d %d %d %d\n",n,lch,rch,seg[lch].sum1,seg[rch].sum1);
    seg[n].sum0=seg[lch].sum0+seg[rch].sum0;
    seg[n].sum1=seg[lch].sum1+seg[rch].sum1;
}
void build(int l,int r,int num)
{
	seg[num].rev=0;
    if(l==r)
    {
        seg[num].sum0=1; seg[num].sum1=0;
        return;
    }
    int mid=(l+r)>>1;
    seg[num].lch=++tot;
    build(l,mid,tot);
    seg[num].rch=++tot;
    build(mid+1,r,tot);
    upd(num);
}

void relax(int n,int now)
{

    int lch=seg[n].lch, rch=seg[n].rch,l=seg[now].lch,r=seg[now].rch;
    //	printf("==%d	%d	%d %d %d	%d? %d\n",now,n,lch,l,r,rch,seg[n].rev);
		//���´������Ƹ���
    if(seg[now].rev==0){
		seg[l].sum0=seg[lch].sum0;
		seg[l].sum1=seg[lch].sum1;
		seg[r].sum0=seg[rch].sum0;
		seg[r].sum1=seg[rch].sum1;
		seg[l].rev=seg[lch].rev;
		seg[r].rev=seg[rch].rev;
    	return;
	}
	//�´���ˢ��
    seg[l].rev=seg[lch].rev^1;
    seg[r].rev=seg[rch].rev^1;
    seg[now].rev=0;
    seg[l].sum0=seg[lch].sum1;
    seg[l].sum1=seg[lch].sum0;
    seg[r].sum0=seg[rch].sum1;
    seg[r].sum1=seg[rch].sum0;
//	printf("+ %d	%d\n",seg[lch].sum0,seg[rch].sum0);
}

void update(int l,int r,int pos,int pre,int now,int a,int b)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(l==r&&l==pos)
    {
    //	printf("..%d %d %d.\n",pre,now,pos);
        seg[now].sum0=a; seg[now].sum1=b;
        seg[now].rev=0;
        return;
    }
    if(l<=pos&&pos<=r)
    {
        seg[now].lch=++tot;
		seg[now].rch=++tot;
        relax(pre,now);
        update(l,m,pos,seg[pre].lch,seg[now].lch,a,b);
		update(m+1,r,pos,seg[pre].rch,seg[now].rch,a,b);
		upd(now);
    }
   // printf("%d  %d  %d  %d  %d\n",l,r,pos,now,pre);
}

void revers(int l,int r,int ll,int rr,int pre,int now)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(ll<=l&&r<=rr)
    {
        seg[now].rev^=1;
        //printf("--%d %d %d %d\n",ll,rr,now,seg[now].rev);
        seg[now].sum0=seg[pre].sum1;
        seg[now].sum1=seg[pre].sum0;
        return;
    }
    if(l<=rr&&ll<=r)
    {
        seg[now].lch=++tot;
        seg[now].rch=++tot;
        relax(pre,now);
        revers(l,m,ll,rr,seg[pre].lch,seg[now].lch);
        revers(m+1,r,ll,rr,seg[pre].rch,seg[now].rch);
		upd(now);
    }
    //printf("%d  %d  %d  %d  %d  %d\n",l,r,ll,rr,now,pre);
}

int main()
{
    int n,m,i,j,q,oper,k;
   // freopen("out.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&q);
    build(1,n*m,tot);
    for(k=1;k<=q;k++)
    {
        scanf("%d",&oper);
        switch(oper)
        {
            case 1: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],0,1);
                    break;
            case 2: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],1,0);
                    break;
            case 3: scanf("%d",&i);
                    root[k]=++tot;
                    revers(1,n*m,(i-1)*m+1,i*m,root[k-1],root[k]);
                    break;
            case 4: scanf("%d",&i);
                    root[k]=root[i];
        }
        printf("%d\n",seg[root[k]].sum1);
    }
    return 0;
}
/*
4 2 100
1 1 2
3 1
3 2
3 1
3 2
2 2 1
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int root[100100],tot;
struct node
{
    int lch,rch,rev,sum1,sum0;
}seg[20000100];
void upd(int n)
{
    int lch=seg[n].lch, rch=seg[n].rch;
    //printf("0.0 %d %d %d %d %d\n",n,lch,rch,seg[lch].sum1,seg[rch].sum1);
    seg[n].sum0=seg[lch].sum0+seg[rch].sum0;
    seg[n].sum1=seg[lch].sum1+seg[rch].sum1;
}
void build(int l,int r,int num)
{
	seg[num].rev=0;
    if(l==r)
    {
        seg[num].sum0=1; seg[num].sum1=0;
        return;
    }
    int mid=(l+r)>>1;
    seg[num].lch=++tot;
    build(l,mid,tot);
    seg[num].rch=++tot;
    build(mid+1,r,tot);
    upd(num);
}

void relax(int n,int now)
{

    int lch=seg[n].lch, rch=seg[n].rch,l=seg[now].lch,r=seg[now].rch;
    //	printf("==%d	%d	%d %d %d	%d? %d\n",now,n,lch,l,r,rch,seg[n].rev);
		//���´������Ƹ���
    if(seg[now].rev==0){
		seg[l].sum0=seg[lch].sum0;
		seg[l].sum1=seg[lch].sum1;
		seg[r].sum0=seg[rch].sum0;
		seg[r].sum1=seg[rch].sum1;
		seg[l].rev=seg[lch].rev;
		seg[r].rev=seg[rch].rev;
    	return;
	}
	//�´���ˢ��
    seg[l].rev=seg[lch].rev^1;
    seg[r].rev=seg[rch].rev^1;
    seg[now].rev=0;
    seg[l].sum0=seg[lch].sum1;
    seg[l].sum1=seg[lch].sum0;
    seg[r].sum0=seg[rch].sum1;
    seg[r].sum1=seg[rch].sum0;
//	printf("+ %d	%d\n",seg[lch].sum0,seg[rch].sum0);
}

void update(int l,int r,int pos,int pre,int now,int a,int b)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(l==r&&l==pos)
    {
    //	printf("..%d %d %d.\n",pre,now,pos);
        seg[now].sum0=a; seg[now].sum1=b;
        seg[now].rev=0;
        return;
    }
    if(l<=pos&&pos<=r)
    {
        seg[now].lch=++tot;
		seg[now].rch=++tot;
        relax(pre,now);
        update(l,m,pos,seg[pre].lch,seg[now].lch,a,b);
		update(m+1,r,pos,seg[pre].rch,seg[now].rch,a,b);
		upd(now);
    }
   // printf("%d  %d  %d  %d  %d\n",l,r,pos,now,pre);
}

void revers(int l,int r,int ll,int rr,int pre,int now)
{
    int m=(l+r)>>1;
    seg[now].lch=seg[pre].lch;
    seg[now].rch=seg[pre].rch;
    if(ll<=l&&r<=rr)
    {
        seg[now].rev^=1;
        //printf("--%d %d %d %d\n",ll,rr,now,seg[now].rev);
        seg[now].sum0=seg[pre].sum1;
        seg[now].sum1=seg[pre].sum0;
        return;
    }
    if(l<=rr&&ll<=r)
    {
        seg[now].lch=++tot;
        seg[now].rch=++tot;
        relax(pre,now);
        revers(l,m,ll,rr,seg[pre].lch,seg[now].lch);
        revers(m+1,r,ll,rr,seg[pre].rch,seg[now].rch);
		upd(now);
    }
    //printf("%d  %d  %d  %d  %d  %d\n",l,r,ll,rr,now,pre);
}

int main()
{
    int n,m,i,j,q,oper,k;
   // freopen("out.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&q);
    build(1,n*m,tot);
    for(k=1;k<=q;k++)
    {
        scanf("%d",&oper);
        switch(oper)
        {
            case 1: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],0,1);
                    break;
            case 2: scanf("%d%d",&i,&j);
                    root[k]=++tot;
                    update(1,n*m,(i-1)*m+j,root[k-1],root[k],1,0);
                    break;
            case 3: scanf("%d",&i);
                    root[k]=++tot;
                    revers(1,n*m,(i-1)*m+1,i*m,root[k-1],root[k]);
                    break;
            case 4: scanf("%d",&i);
                    root[k]=root[i];
        }
        printf("%d\n",seg[root[k]].sum1);
    }
    return 0;
}
/*
4 2 100
1 1 2
3 1
3 2
3 1
3 2
2 2 1
*/


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 100007
int n , m , q ;

struct Tree {
    Tree *pl , *pr ;
    int IL , IR ;
    int br ;
    int lazy ;
    Tree ( ) {
        this->IL = this->IR = this->br = 0 ;
        this->lazy = 0 ;
        this->pl = this->pr = NULL ;
    }
    Tree ( int x , int y ) {
            printf ( "%d %d\n" , x , y ) ;
        this->IL = x ;
        this->IR = y ;
        this->br = 0 ;
        this->lazy = 0 ;
        this->pl = this->pr = NULL ;
        if ( x == y ) { return ; }
        int mid = ( x + y ) / 2 ;
        this->pl = new Tree ( x , mid ) ;
        this->pr = new Tree ( mid + 1 , y ) ;
    }
    void merge ( ) {
        //if ( this->IL == this->IR ) { return ; }
        this->br = this->pl->br + this->pr->br ;
    }
    void push_lazy ( ) {
        if ( this->lazy == 0 ) { return ; }
        this->br = ( IR - IL + 1 ) - this->br ;
        if ( this->IL != this->IR ) {
            this->pl->lazy ^= 1 ;
            this->pr->lazy ^= 1 ;
        }
        this->lazy = 0 ;
    }
};

Tree* pos_update ( Tree *w , int pos , int val ) {
    w->push_lazy ( ) ;
    if ( w->IR < pos || pos < w->IL ) { return w ; }
    if ( w->IL == w->IR ) {
        Tree *ret = new Tree ( ) ;
        ret->IL = w->IL ;
        ret->IR = w->IR ;
        ret->br = val ;
        ret->lazy = 0 ;
        ret->pl = ret->pr = NULL ;
        return ret ;
    }
    Tree *ret = new Tree ( ) ;
    ret->pl = pos_update ( w->pl , pos , val ) ;
    ret->pr = pos_update ( w->pr , pos , val ) ;
    ret->merge ( ) ;
    return ret ;
}

Tree* antitree ( Tree *w ) {
    Tree *ret = new Tree ( ) ;
    ret->IL = w->IL ;
    ret->IR = w->IR ;
    ret->br = ( w->IR - w->IL + 1 ) - w->br ;
    ret->pl = ret->pr = NULL ;
    if ( w->IL == w->IR ) { return ret ; }
    ret->pl = antitree ( w->pl ) ;
    ret->pr = antitree ( w->pr ) ;
    //ret->merge ( ) ;
    return ret ;
}

int tot[ MAXN ] ;

struct router {
    Tree *root[ 1002 ] ;
};

router *init[ MAXN ] ;

void input ( ) {
    scanf ( "%d%d%d" , &n , &m , &q ) ;
}

void solve ( ) {
    int i , j ;
    init[ 0 ] = new router ;
    for ( i = 1 ; i <= n ; i ++ ) {
        init[ 0 ]->root[ i ] = new Tree ( 1 , m ) ;
    }
    for ( i = 1 ; i <= q ; i ++ ) {
        init[ i ] = init[ i - 1 ] ;
        tot[ i ] = tot[ i - 1 ] ;
        int type ;
        scanf ( "%d" , &type ) ;
        if ( type == 1 ) {
            int x , y ;
            scanf ( "%d%d" , &x , &y ) ;
            tot[ i ] -= init[ i ]->root[ x ]->br ;
            init[ i ]->root[ x ] = pos_update ( init[ i ]->root[ x ] , y , 1 ) ;
            tot[ i ] += init[ i ]->root[ x ]->br ;
        }
        else if ( type == 2 ) {
            int x , y ;
            scanf ( "%d%d" , &x , &y ) ;
            tot[ i ] -= init[ i ]->root[ x ]->br ;
            init[ i ]->root[ x ] = pos_update ( init[ i ]->root[ x ] , y , 0 ) ;
            tot[ i ] += init[ i ]->root[ x ]->br ;

        }
        else if ( type == 3 ) {
            int x ;
            scanf ( "%d" , &x ) ;
            tot[ i ] -= init[ i ]->root[ x ]->br ;
            init[ i ]->root[ x ] = antitree ( init[ i ]->root[ x ] ) ;
            tot[ i ] += init[ i ]->root[ x ]->br ;
        }
        else {
            int x ;
            scanf ( "%d" , &x ) ;
            init[ i ] = init[ x ] ;
            tot[ i ] = tot[ x ] ;
        }
        printf ( "%d\n" , tot[ i ] ) ;
    }
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 100007
int n , m , q ;

struct Tree {
    Tree *pl , *pr ;
    int IL , IR ;
    int br ;
    int lazy ;
    Tree ( ) {
        this->IL = this->IR = this->br = 0 ;
        this->lazy = 0 ;
        this->pl = this->pr = NULL ;
    }
    Tree ( int x , int y ) {
        this->IL = x ;
        this->IR = y ;
        this->br = 0 ;
        this->lazy = 0 ;
        this->pl = this->pr = NULL ;
        if ( x == y ) { return ; }
        int mid = ( x + y ) / 2 ;
        this->pl = new Tree ( x , mid ) ;
        this->pr = new Tree ( mid + 1 , y ) ;
    }
    void merge ( ) {
        //if ( this->IL == this->IR ) { return ; }
        this->br = this->pl->br + this->pr->br ;
    }
    void push_lazy ( ) {
        if ( this->lazy == 0 ) { return ; }
        this->br = ( IR - IL + 1 ) - this->br ;
        if ( this->IL != this->IR ) {
            this->pl->lazy ^= 1 ;
            this->pr->lazy ^= 1 ;
        }
        this->lazy = 0 ;
    }
};

Tree* pos_update ( Tree *w , int pos , int val ) {
    w->push_lazy ( ) ;
    if ( w->IR < pos || pos < w->IL ) { return w ; }
    if ( w->IL == w->IR ) {
        Tree *ret = new Tree ( ) ;
        ret->IL = w->IL ;
        ret->IR = w->IR ;
        ret->br = val ;
        ret->lazy = 0 ;
        ret->pl = ret->pr = NULL ;
        return ret ;
    }
    Tree *ret = new Tree ( ) ;
    ret->IL = w->IL ;
    ret->IR = w->IR ;
    ret->br = 0 ;
    ret->lazy = 0 ;
    ret->pl = pos_update ( w->pl , pos , val ) ;
    ret->pr = pos_update ( w->pr , pos , val ) ;
    ret->merge ( ) ;
    return ret ;
}

Tree* antitree ( Tree *w ) {
    Tree *ret = new Tree ( ) ;
    ret->IL = w->IL ;
    ret->IR = w->IR ;
    ret->br = ( w->IR - w->IL + 1 ) - w->br ;
    ret->pl = ret->pr = NULL ;
    if ( w->IL == w->IR ) { return ret ; }
    ret->pl = antitree ( w->pl ) ;
    ret->pr = antitree ( w->pr ) ;
    ret->merge ( ) ;
    return ret ;
}

int tot[ MAXN ] ;

struct router {
    Tree *root[ 1002 ] ;
};

router init[ MAXN ] ;

void input ( ) {
    scanf ( "%d%d%d" , &n , &m , &q ) ;
}

void solve ( ) {
    int i , j ;
    for ( i = 1 ; i <= n ; i ++ ) {
        init[ 0 ].root[ i ] = new Tree ( 1 , m ) ;
    }
    for ( i = 1 ; i <= q ; i ++ ) {
        init[ i ] = init[ i - 1 ] ;
        tot[ i ] = tot[ i - 1 ] ;
        int type ;
        scanf ( "%d" , &type ) ;
        if ( type == 1 ) {
            int x , y ;
            scanf ( "%d%d" , &x , &y ) ;
            tot[ i ] -= init[ i ].root[ x ]->br ;
            init[ i ].root[ x ] = pos_update ( init[ i ].root[ x ] , y , 1 ) ;
            tot[ i ] += init[ i ].root[ x ]->br ;
        }
        else if ( type == 2 ) {
            int x , y ;
            scanf ( "%d%d" , &x , &y ) ;
            tot[ i ] -= init[ i ].root[ x ]->br ;
            init[ i ].root[ x ] = pos_update ( init[ i ].root[ x ] , y , 0 ) ;
            tot[ i ] += init[ i ].root[ x ]->br ;

        }
        else if ( type == 3 ) {
            int x ;
            scanf ( "%d" , &x ) ;
            tot[ i ] -= init[ i ].root[ x ]->br ;
            init[ i ].root[ x ] = antitree ( init[ i ].root[ x ] ) ;
            tot[ i ] += init[ i ].root[ x ]->br ;
        }
        else {
            int x ;
            scanf ( "%d" , &x ) ;
            init[ i ] = init[ x ] ;
            tot[ i ] = tot[ x ] ;
        }
        printf ( "%d\n" , tot[ i ] ) ;
    }
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 100007
int n , m , q ;
vector < int > v[ MAXN ] ;
struct tuhla {
    int type ;
    int x , y ;
};

tuhla a[ MAXN ] ;

class Tree {
    public :
    int tr[ 6007 ] ;
    int lazy[ 6007 ] ;
    void init ( int where , int IL , int IR ) {
        tr[ where ] = lazy[ where ] = 0 ;
        if ( IL == IR ) { return ; }
        int mid = ( IL + IR ) / 2 ;
        init ( 2 * where , IL , mid ) ;
        init ( 2 * where + 1 , mid + 1 , IR ) ;
    }
    void push_lazy ( int where , int IL , int IR ) {
        if ( lazy[ where ] == 0 ) { return ; }
        tr[ where ] = ( IR - IL + 1 ) - tr[ where ] ;
        if ( IL != IR ) {
            lazy[ 2 * where ] ^= 1 ;
            lazy[ 2 * where + 1 ] ^= 1 ;
        }
        lazy[ where ] = 0 ;
    }
    int update ( int where , int IL , int IR , int pos , int val ) {
        push_lazy ( where , IL , IR ) ;
        if ( IR < pos || pos < IL ) { return -1 ; }
        if ( IL == IR ) {
            int ret = tr[ where ] ;
            tr[ where ] = val ;
            return ret ;
        }
        int mid = ( IL + IR ) / 2 ;
        int ret = update ( 2 * where , IL , mid , pos , val ) ;
        ret = max ( ret , update ( 2 * where + 1 , mid + 1 , IR , pos , val ) ) ;
        tr[ where ] = tr[ 2 * where ] + tr[ 2 * where + 1 ] ;
        return ret ;
    }
};
Tree w[ 1007 ] ;
int tot = 0 ;
int ans[ MAXN ] ;

void dfs ( int vertex ) {
    int lstval = -1 ;
    tot -= w[ a[ vertex ].x ].tr[ 1 ] ;
    if ( a[ vertex ].type == 1 ) {
        lstval = w[ a[ vertex ].x ].update ( 1 , 1 , m , a[ vertex ].y , 1 ) ;
    }
    else if ( a[ vertex ].type == 2 ) {
        lstval = w[ a[ vertex ].x ].update ( 1 , 1 , m , a[ vertex ].y , 0 ) ;
    }
    else if ( a[ vertex ].type == 3 ) {
        w[ a[ vertex ].x ].lazy[ 1 ] ^= 1 ;
        w[ a[ vertex ].x ].push_lazy ( 1 , 1 , m ) ;
    }
    tot += w[ a[ vertex ].x ].tr[ 1 ] ;
    ans[ vertex ] = tot ;

    int i , sz ;
    sz = v[ vertex ].size ( ) ;
    for ( i = 0 ; i < sz ; i ++ ) {
        dfs ( v[ vertex ][ i ] ) ;
    }

    tot -= w[ a[ vertex ].x ].tr[ 1 ] ;
    if ( a[ vertex ].type == 1 ) {
        w[ a[ vertex ].x ].update ( 1 , 1 , m , a[ vertex ].y , lstval ) ;
    }
    else if ( a[ vertex ].type == 2 ) {
        w[ a[ vertex ].x ].update ( 1 , 1 , m , a[ vertex ].y , lstval ) ;
    }
    else if ( a[ vertex ].type == 3 ) {
        w[ a[ vertex ].x ].lazy[ 1 ] ^= 1 ;
        w[ a[ vertex ].x ].push_lazy ( 1 , 1 , m ) ;
    }
    tot += w[ a[ vertex ].x ].tr[ 1 ] ;
}

void input ( ) {
    scanf ( "%d%d%d" , &n , &m , &q ) ;
    int i ;
    for ( i = 1 ; i <= q ; i ++ ) {
        scanf ( "%d" , &a[ i ].type ) ;
        if ( a[ i ].type == 1 ) {
            scanf ( "%d%d" , &a[ i ].x , &a[ i ].y ) ;
            v[ i - 1 ].push_back ( i ) ;
        }
        else if ( a[ i ].type == 2 ) {
            scanf ( "%d%d" , &a[ i ].x , &a[ i ].y ) ;
            v[ i - 1 ].push_back ( i ) ;
        }
        else if ( a[ i ].type == 3 ) {
            scanf ( "%d" , &a[ i ].x ) ;
            v[ i - 1 ].push_back ( i ) ;
        }
        else {
            scanf ( "%d" , &a[ i ].x ) ;
            v[ a[ i ].x ].push_back ( i ) ;
        }
    }
}

void solve ( ) {
    int i ;
    w[ 0 ].init ( 1 , 1 , m ) ;
    for ( i = 1 ; i <= n ; i ++ ) {
        w[ i ].init ( 1 , 1 , m ) ;
    }
    dfs ( 0 ) ;
    for ( i = 1 ; i <= q ; i ++ ) {
        printf ( "%d\n" , ans[ i ] ) ;
    }
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t,i;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        int n,m,j,k,num_j[51]={0},num_k[51]={0},turn=0;
        scanf("%d%d",&n,&m);
        for(j=1;j<=n;j++){
            for(k=1;k<=m;k++){
                int n1;
                scanf("%d",&n1);
                if(n1==1){
                    num_j[j]=1;
                    num_k[k]=1;
                }
            }
        }
       for(j=1;j<=n;j++){
        if(num_j[j]==1)
            continue;
        else{
            for(k=1;k<=m;k++){
                if(num_k[k]==0){
                    //printf("111\n");
                    num_k[k]=1;
                    turn++;
                    break;
                }
            }
        }
       }
       printf("%d\n",turn);
       if(turn%2==0)
        printf("Vivek\n");
       else
        printf("Ashish\n");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t,i;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        int n,m,j,k,num_j[51]={0},num_k[51]={0},turn=0;
        scanf("%d%d",&n,&m);
        for(j=1;j<=n;j++){
            for(k=1;k<=m;k++){
                int n1;
                scanf("%d",&n1);
                if(n1==1){
                    num_j[j]=1;
                    num_k[k]=1;
                }
            }
        }
       for(j=1;j<=n;j++){
        if(num_j[j]==1)
            continue;
        else{
            for(k=1;k<=m;k++){
                if(num_k[k]==0){
                    //printf("111\n");
                    num_k[k]=1;
                    turn++;
                    break;
                }
            }
        }
       }
       //printf("%d\n",turn);
       if(turn%2==0)
        printf("Vivek\n");
       else
        printf("Ashish\n");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t,i;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        int n,m,j,k,num_j[51]={0},num_k[51]={0},turn=0;
        scanf("%d%d",&n,&m);
        for(j=1;j<=n;j++){
            for(k=1;k<=m;k++){
                int n1;
                scanf("%d",&n1);
                if(n1==1){
                    num_j[j]=1;
                    num_k[k]=1;
                }
            }
        }
       for(j=1;j<=n;j++){
        if(num_j[j]==1)
            continue;
        else{
            for(k=1;k<=m;k++){
                if(num_k[k]==0){
                    num_k[k]==1;
                    turn++;
                    break;
                }
            }
        }
       }
       if(turn%2==0)
        printf("Vivek\n");
       else
        printf("Ashish\n");
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int test;
scanf("%d",&test);
for(int i=0;i<test;i++)
{
int row,colum;
scanf("%d %d",&row,&colum);
int *arr=(int *)malloc(sizeof(int )*row*colum);
 for(int j=0;j<row;j++)
 {
 for(int k=0;k<colum;k++)
 {
  scanf("%d",arr+j*colum+k);
 }
 }
 /*for(int j=0;j<row;j++)
 {
 for(int k=0;k<colum;k++)
 {
  printf("%d",*(arr+j*colum+k));
 }*/
 int *arr1=(int *)calloc(row,sizeof(int));
 int *arr2=(int *)calloc(colum,sizeof(int));
 //memset(arr1,0,row);
 //memset(arr2,0,colum);

 for(int j=0;j<row;j++)
 {
 for(int k=0;k<colum;k++)
 {
  if(*(arr+j*colum+k)== 1)
  {
      arr1[j]=1;
      arr2[k]=1;
  }
 /* else
    {
        arr1[j]=0;
      arr2[k]=0;

    }*/

 }
 }
/* for(int j=0;j<row;j++)
    printf("%d",*(arr1 + j));
    printf("\n");
 for(int k=0;k<colum;k++)
    printf("%d",*(arr2+k));*/

    int i=0,j=0;
   int   count=1;
    while(i<row)
    {
        if(arr1[i]==0)
        {

          while(j<colum)
          {
              if(arr2[j]==0)
              {
                  count++;
                  arr1[i]=1;
                  arr2[j]=1;
                  break;
              }
           j++;
          }
        }
        i++;

    }

    if(count%2==0)
        printf("Ashish\n");
    else
    printf("Vivek\n");
 }

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int test;
scanf("%d",&test);
for(int i=0;i<test;i++)
{
int row,colum;
scanf("%d %d",&row,&colum);
int *arr=(int *)malloc(sizeof(int )*row*colum);
 for(int j=0;j<row;j++)
 {
 for(int k=0;k<colum;k++)
 {
  scanf("%d",arr+j*colum+k);
 }
 }
 /*for(int j=0;j<row;j++)
 {
 for(int k=0;k<colum;k++)
 {
  printf("%d",*(arr+j*colum+k));
 }*/
 int *arr1=(int *)calloc(row,sizeof(int));
 int *arr2=(int *)calloc(colum,sizeof(int));
 //memset(arr1,0,row);
 //memset(arr2,0,colum);

 for(int j=0;j<row;j++)
 {
 for(int k=0;k<colum;k++)
 {
  if(*(arr+j*colum+k)== 1)
  {
      arr1[j]=1;
      arr2[k]=1;
  }
 /* else
    {
        arr1[j]=0;
      arr2[k]=0;

    }*/

 }
 }
/* for(int j=0;j<row;j++)
    printf("%d",*(arr1 + j));
    printf("\n");
 for(int k=0;k<colum;k++)
    printf("%d",*(arr2+k));*/

    int i=0,j=0;
   int   count=1;
    while(i<row)
    {
        if(arr1[i]==0)
        {

          while(j<colum)
          {
              if(arr2[j]==0)
              {
                  count++;
                  arr1[i]=1;
                  arr2[j]=1;
                  break;
              }
          }
        }
        i++;
        j++;
    }

    if(count%2==0)
        printf("Ashish\n");
    else
    printf("Vivek\n");
 }

}


#include<stdio.h>
int main(void)
{
    int t ; scanf("%d",&t) ;
    while(t--)
    {
        int row , col ; scanf("%d %d",&row,&col) ;
        int score[row][col] , i , j , cnt = 0 , cnt2 = 0 ;
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                scanf("%d",&score[i][j]) ;
            }
        }
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                if(!score[i][j]){++cnt ; }
                if(cnt == col){++cnt2 ; }
            }
            cnt = 0 ;
        }
        if(!cnt2){printf("Vivek\n") ; }
        else if(cnt2 % 2){printf("Ashish\n") ; }
        else if(!(cnt2 % 2)){printf("Vivek\n") ; }
    }
    return 0 ;
}


#include<stdio.h>
int main(void)
{
    int t ; scanf("%d",&t) ;
    while(t--)
    {
        int row , col ; scanf("%d %d",&row,&col) ;
        int score[row][col] , i , j , cnt = 0 ;
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                scanf("%d",&score[i][j]) ;
                if(!score[i][j]){++cnt ; }
            }
        }
        if(cnt % 2){printf("Ashish\n") ; }
        else{printf("Vivek\n") ; }
    }
    return 0 ;
}


#include<stdio.h>
int main(void)
{
    int t ; scanf("%d",&t) ;
    while(t--)
    {
        int row , col ; scanf("%d %d",&row,&col) ;
        int score[row][col] , i , j , cnt = 0 , cnt2 = 0 ;
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                scanf("%d",&score[i][j]) ;
            }
        }
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                if(!score[i][j]){++cnt ; }
                if(cnt == col){++cnt2 ; }
            }
            cnt = 0 ;
        }
        if(!cnt2)
        {
            for(j = 0 ; j < col ; ++j)
            {
                for(i = 0 ; i < row ; ++i)
                {
                    if(!score[i][j]){++cnt ; }
                    if(cnt == row){++cnt2 ; }
                }
                cnt = 0 ;
            }
        }
        if(cnt2 % 2){printf("Ashish\n") ; }
        else if(!(cnt2 % 2)){printf("Vivek\n") ; }
    }
    return 0 ;
}


#include<stdio.h>
int main(void)
{
    int t ; scanf("%d",&t) ;
    while(t--)
    {
        int row , col ; scanf("%d %d",&row,&col) ;
        int score[row][col] , i , j , cnt = 0 , cnt2 = 0 , x = 0 , y = 0 ;
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                scanf("%d",&score[i][j]) ;
            }
        }
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                if(!score[i][j]){++cnt ; }
                if(cnt == col){++x ; }
            }
            cnt = 0 ;
        }

            for(j = 0 ; j < col ; ++j)
            {
                for(i = 0 ; i < row ; ++i)
                {
                    if(!score[i][j]){++cnt ; }
                    if(cnt == row){++y ; }
                }
                cnt = 0 ;
            }

            cnt2 = (x <= y)? x : y ;

        if(cnt2 % 2){printf("Ashish\n") ; }
        else if(!(cnt2 % 2)){printf("Vivek\n") ; }
    }
    return 0 ;
}


#include<stdio.h>
int main(void)
{
    int t ; scanf("%d",&t) ;
    while(t--)
    {
        int row , col ; scanf("%d %d",&row,&col) ;
        int score[row][col] , i , j , cnt = 0 , cnt2 = 0 ;
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                scanf("%d",&score[i][j]) ;
            }
        }
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                if(!score[i][j]){++cnt ; }
                if(cnt == col){++cnt2 ; }
            }
            cnt = 0 ;
        }
        if(cnt2 % 2){printf("Ashish\n") ; }
        else if(!(cnt2 % 2)){printf("Vivek\n") ; }
    }
    return 0 ;
}


#include<stdio.h>
int main(void)
{
    int t ; scanf("%d",&t) ;
    while(t--)
    {
        int row , col ; scanf("%d %d",&row,&col) ;
        int score[row][col] , i , j , cnt = 0 ;
        for(i = 0 ; i < row ; ++i)
        {
            for(j = 0 ; j < col ; ++j)
            {
                scanf("%d",&score[i][j]) ;
                if(!score[i][j]){++cnt ; }
            }
        }
        if(!cnt){printf("Vivek\n") ; }
        else if(cnt % 2){printf("Ashish\n") ; }
        else{printf("Vivek\n") ; }
    }
    return 0 ;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    int m, n, i, j, t, count1, count2, max, maxi;
    scanf("%d", &t);
    while(t--){
        int **a, *row, *col;
        count1=0;
        count2=0;
        scanf("%d%d", &m, &n);
        row=(int *)malloc(m*sizeof(int));
        col=(int *)malloc(n*sizeof(int));
        for(i=0;i<m;i++)
         row[i]=0;
        for(i=0;i<n;i++)
         col[i]=0;
        a=(int **)malloc(m*sizeof(int *));
        for(i=0;i<m;i++)
         a[i]=(int *)malloc(n*sizeof(int));
        for(i=0;i<m;i++){
         for(j=0;j<n;j++){
          scanf("%d", &a[i][j]);
          if(a[i][j]==1){
              row[i]=1;
              col[j]=1;
          }

         }
        }
        for(i=0;i<m;i++){
         if(row[i]==1)
          count1++;
        }
        for(i=0;i<n;i++){
         if(col[i]==1)
          count2++;
        }
        max=((m-count1)<=(n-count2))?(m-count1):(n-count2);

        if(max%2!=0)
         printf("Ashish\n");
        else
         printf("Vivek\n");
         free(a);
         free(row);
         free(col);
    }
return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    int m, n, i, j, t, count1, count2, max, maxi;
    scanf("%d", &t);
    while(t--){
        int **a, *row, *col;
        count1=0;
        count2=0;
        scanf("%d%d", &m, &n);
        row=(int *)malloc(m*sizeof(int));
        col=(int *)malloc(n*sizeof(int));
        for(i=0;i<m;i++)
         row[i]=0;
        for(i=0;i<n;i++)
         col[i]=0;
        a=(int **)malloc(m*sizeof(int *));
        for(i=0;i<m;i++)
         a[i]=(int *)malloc(n*sizeof(int));
        for(i=0;i<m;i++){
         for(j=0;j<n;j++){
          scanf("%d", &a[i][j]);
          if(a[i][j]==1){
              row[i]=1;
              col[j]=1;
          }

         }
        }
        for(i=0;i<m;i++){
         if(row[i]==1)
          count1++;
        }
        for(i=0;i<n;i++){
         if(col[i]==1)
          count2++;
        }
        max=((m-count1)>=(n-count2))?(m-count1):(n-count2);

        if(max%2!=0)
         printf("Ashish\n");
        else
         printf("Vivek\n");
         free(a);
         free(row);
         free(col);
    }
return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    int m, n, i, j, t, count1, count2, max, maxi;
    scanf("%d", &t);
    while(t--){
        int **a, *row, *col;
        count1=0;
        count2=0;
        scanf("%d%d", &m, &n);
        row=(int *)malloc(m*sizeof(int));
        col=(int *)malloc(n*sizeof(int));
        for(i=0;i<m;i++)
         row[i]=0;
        for(i=0;i<n;i++)
         col[i]=0;
        a=(int **)malloc(m*sizeof(int *));
        for(i=0;i<m;i++)
         a[i]=(int *)malloc(n*sizeof(int));
        for(i=0;i<m;i++){
         for(j=0;j<n;j++){
          scanf("%d", &a[i][j]);
          if(a[i][j]==1){
              row[i]=1;
              col[j]=1;
          }

         }
        }
        for(i=0;i<m;i++){
         if(row[i]==1)
          count1++;
        }
        for(i=0;i<n;i++){
         if(col[i]==1)
          count2++;
        }
        max=(count1>count2)?count1:count2;
        maxi=(count1>count2)?m:n;
        if((maxi-max)%2!=0)
         printf("Ashish\n");
        else
         printf("Vivek\n");
         free(a);
         free(row);
         free(col);
    }
return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main() {
    int t, r, c, **arr, i, j, k, e, d, f, win;
    scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &r, &c);
        arr = (int**)malloc(r * sizeof(int *));
        for (i = 0; i < r; i++)
            arr[i] = (int *)malloc(c * sizeof(int));
        for(i = 0; i < r; i++) {
            for(j = 0; j < c; j++)
                scanf("%d", &arr[i][j]);
        }
        win = 0;
        for(i = 0; i < r; i++) {
            if(arr[i][0] == 0) {
                d = 0;
                for(j = 1; j < c; j++) {
                    if(arr[i][j] == 1) {
                        d++;
                        break;
                    }
                }
                e = 0;
                if(d == 0) {
                    while(e < c) {
                        f = 0;
                        for(j = 0; j < r; j++) {
                            if(arr[j][e] == 1) {
                                f = 1;
                                break;
                            }
                        }
                        if(f == 0) {
                            arr[i][e] = 1;
                            win++;
                            break;
                        }
                        e++;
                    }
                }
            }
        }
        if(win % 2 == 0)
            printf("Vivek\n");
        else
            printf("Ashish\n");
    }
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int n,m;
	    scanf("%d %d",&n,&m);
	    int a[50][50];
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            scanf("%d",&a[i][j]);
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[i][j]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[j][i]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    int count=0;
	    int min=51;
	    if(n>=m)
	    {
	        min=m;
	    }
	    else
	    {
	        min=n;
	    }
	    for(int i=0; i<min; i++)
	    {
	        if(a[i][i]==0)
	        {
	            count++;
	        }
	    }

	    if(count%2==0)
	    {
	        printf("Vivek\n");
	    }
	    else
	    {
	        printf("Ashish\n");
	    }
	}
	return 0;
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int n,m;
	    scanf("%d %d",&n,&m);
	    int a[50][50];
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            scanf("%d",&a[i][j]);
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[i][j]==1)
	            {
	                a[i][i]=1;
	            }
	            if(a[j][i]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    int count=0;
	    int min=51;
	    if(n>=m)
	    {
	        min=m;
	    }
	    else
	    {
	        min=n;
	    }
	    for(int i=0; i<min; i++)
	    {
	        if(a[i][i]==0)
	        {
	            count++;
	        }
	    }

	    if(count%2==0)
	    {
	        printf("Vivek\n");
	    }
	    else
	    {
	        printf("Ashish\n");
	    }
	}
	return 0;
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int n,m;
	    scanf("%d %d",&n,&m);
	    int a[n][m];
	    int row=n,column=m,count=0;
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            scanf("%d",&a[i][j]);
	            if(a[i][j]==1)
	            count++;
	        }
	        if(count>0)
	        {
	            row--;
	        }
	        count=0;
	    }
	    for(int i=0; i<m; i++)
	    {
	        for(int j=0; j<n; j++)
	        {
	            if(a[j][i]==1)
	            count++;
	        }
	        if(count>0)
	        {
	            column--;
	        }
	        count=0;
	    }
	    int min=51;
	    if(row>column)
	    {
	        min=column;
	    }
	    else
	    {
	        min=row;
	    }
	    if(min%2==0)
	    {
	        printf("Vivek\n");
	    }
	    else
	    {
	        printf("Ashish\n");
	    }
	}
	return 0;
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int n,m;
	    scanf("%d %d",&n,&m);
	    int a[n][m];
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            scanf("%d",&a[i][j]);
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[i][j]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[j][i]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    int count=0;
	    for(int i=0; i<n; i++)
	    {
	        if(a[i][i]==0)
	        {
	            count++;
	        }
	    }

	    if(count%2==0)
	    {
	        printf("Vivek\n");
	    }
	    else
	    {
	        printf("Ashish\n");
	    }
	}
	return 0;
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int n,m;
	    scanf("%d %d",&n,&m);
	    int a[n][m];
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            scanf("%d",&a[i][j]);
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[i][j]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    for(int i=0; i<n; i++)
	    {
	        for(int j=0; j<m; j++)
	        {
	            if(a[j][i]==1)
	            {
	                a[i][i]=1;
	            }
	        }
	    }
	    int count=0;
	    int min=51;
	    if(n>=m)
	    {
	        min=n;
	    }
	    else
	    {
	        min=m;
	    }
	    for(int i=0; i<min; i++)
	    {
	        if(a[i][i]==0)
	        {
	            count++;
	        }
	    }

	    if(count%2==0)
	    {
	        printf("Vivek\n");
	    }
	    else
	    {
	        printf("Ashish\n");
	    }
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    char p[2][7] = {"Vivek", "Ashish"};
    int t;

    scanf("%d", &t);

    while(t--){
        int n, m;
        int *ns, *ms;
        int x;
        int mc = 0, nc = 0;
        int possible = 0;

        scanf("%d %d", &n ,&m);
        ns = calloc(n, sizeof(int));
        ms = calloc(m, sizeof(int));

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                scanf("%d", &x);
                ns[i] = (ns[i] & -!x) + (1 & -x);
                ms[j] = (ms[j] & -!x) + (1 & -x);
            }
        }
        for(int i = 0; i < n; i++)
            nc += !ns[i];
        for(int i = 0; i < m; i++)
            mc += !ms[i];

        possible = (mc & -(mc < nc)) + (nc & -(nc <= mc));

        printf("%s\n", p[possible & 1]);

        free(ns);
        free(ms);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    char p[2][7] = {"Vivek", "Ashish"};
    int t;

    scanf("%d", &t);

    while(t--){
        int n, m;
        int *ns, *ms;
        int x;
        int mc = 0, nc = 0;
        int possible = 0;

        scanf("%d %d", &n ,&m);
        ns = malloc(sizeof(int) * n);
        ms = malloc(sizeof(int) * m);

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                scanf("%d", &x);
                ns[i] = (ns[i] & -!x) + (1 & -x);
                ms[j] = (ms[j] & -!x) + (1 & -x);
            }
        }
        for(int i = 0; i < n; i++)
            nc += !ns[i];
        for(int i = 0; i < n; i++)
            mc += !ms[i];

        possible = (mc & -(mc < nc)) + (nc & -(nc <= mc));

        printf("%s\n", p[possible & 1]);

    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    char p[2][7] = {"Vivek", "Ashish"};
    int t;

    scanf("%d", &t);

    while(t--){
        int n, m;
        int *ns, *ms;
        int x;
        int mc = 0, nc = 0;
        int possible = 0;

        scanf("%d %d", &n ,&m);
        ns = malloc(sizeof(int) * n);
        ms = malloc(sizeof(int) * m);

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                scanf("%d", &x);
                ns[i] = (ns[i] & -!x) + (1 & -x);
                ms[j] = (ms[j] & -!x) + (1 & -x);
            }
        }
        for(int i = 0; i < n; i++)
            nc += !ns[i];
        for(int i = 0; i < m; i++)
            mc += !ms[i];

        printf("n: ");
        for(int i = 0; i < n; i++)
            printf("%d ", ns[i]);
        printf("\n");
        printf("m: ");
        for(int i = 0; i < m; i++)
            printf("%d ", ms[i]);
        printf("\n");

        printf("nc: %d, mc: %d\n", nc, mc);
        possible = (mc & -(mc < nc)) + (nc & -(nc <= mc));

        printf("%s\n", p[possible & 1]);

    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    char p[2][7] = {"Vivek", "Ashish"};
    int t;

    scanf("%d", &t);

    while(t--){
        int n, m;
        int *ns, *ms;
        int x;
        int mc = 0, nc = 0;
        int possible = 0;

        scanf("%d %d", &n ,&m);
        ns = calloc(n, sizeof(int));
        ms = calloc(m, sizeof(int));

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                scanf("%d", &x);
                ns[i] = (ns[i] & -!x) + (1 & -x);
                ms[j] = (ms[j] & -!x) + (1 & -x);
            }
        }
        for(int i = 0; i < n; i++)
            nc += !ns[i];
        for(int i = 0; i < m; i++)
            mc += !ms[i];

        printf("n: ");
        for(int i = 0; i < n; i++)
            printf("%d ", ns[i]);
        printf("\n");
        printf("m: ");
        for(int i = 0; i < m; i++)
            printf("%d ", ms[i]);
        printf("\n");

        printf("nc: %d, mc: %d\n", nc, mc);
        possible = (mc & -(mc < nc)) + (nc & -(nc <= mc));

        printf("%s\n", p[possible & 1]);

        free(ns);
        free(ms);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    char p[2][7] = {"Vivek", "Ashish"};
    int t;

    scanf("%d", &t);

    while(t--){
        int n, m;
        int *ns, *ms;
        int x;
        int mc = 0, nc = 0;
        int possible = 0;

        scanf("%d %d", &n ,&m);
        ns = malloc(sizeof(int) * n);
        ms = malloc(sizeof(int) * m);

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                scanf("%d", &x);
                ns[i] = (ns[i] & -!x) + (1 & -x);
                ms[j] = (ms[j] & -!x) + (1 & -x);
            }
        }
        for(int i = 0; i < n; i++)
            nc += !ns[i];
        for(int i = 0; i < m; i++)
            mc += !ms[i];

        possible = (mc & -(mc < nc)) + (nc & -(nc <= mc));

        printf("%s\n", p[possible & 1]);

    }

    return 0;
}


#include<stdio.h>
#define MIN(a,b) (a<b)?a:b
#define printd(...) fprintf(stderr,__VA_ARGS__);
char MAP[52][52];

int main(){

	int t;scanf("%d",&t);
	while(t--){
		int n,m;scanf("%d %d",&n,&m);
		for(int i=0;i<n;i++)for(int j=0;j<m;j++)scanf(" %c",&MAP[i][j]);

		int REMn = n;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)if(MAP[i][j]=='1'){
				REMn--;
				break;
			}
		}

		int REMm = m;
		for(int j=0;j<m;j++){
			for(int i=0;i<n;i++)if(MAP[i][j]=='1'){
				REMm--;
				break;
			}
		}

		int REM = MIN(REMn,REMm);

		printd("REM = %d , REMn = %d , REMm %d\n",REM,REMn,REMm)

		if(REM&1)printf("Ashish\n");
		else printf("Vivek\n");

	}
	return 0;

}


#include <stdio.h>

int checkcolumns(int a[50][50], int i, int j)
{
	int i1, j1;
	int cc = 0;
    for(i1 = 0; i1 < j; i1++)
    {
        for(j1 = 0; j1 < i; j1++)
        {
            if(a[j1][i1] == 1)
                break;
            if(a[j1][i1] == 0)
            	cc += 1;
            if(cc == i)
                return i1;
        }
    }
    return -1;
}

int main()
{
	int a[50][50];
    int tc,t;
    scanf("%d",&t);
    for(tc = 1; tc <= t; tc++)
    {
    	int rows, columns;
        scanf("%d%d",&rows,&columns);

        int i,j;
        for(i = 0; i < rows; i++)
        {
        	for(j = 0; j < columns; j++)
        	{
        		scanf("%d",&a[i][j]);
			}
		}
        int c = 0, r = 0;

        for(i = 0; i < rows; i++)
        {
            for(j = 0; j < columns; j++)
            {
                if(a[i][j] == 1)
                    break;
                if(a[i][j] == 0)
                    r += 1;
                if(r == columns)
                {
                    int return1 = checkcolumns(a,rows,columns);
                    if(return1 != -1)
                    {
                        a[i][return1] = 1;
                        c += 1;
                    }
                }
            }
        }
        if(c%2 == 0)
            printf("\"Vivek\"\n");
        else
            printf("\"Ashish\"\n");
    }
}


#include <stdio.h>

int checkcolumns(int a[50][50], int i, int j)
{
	int i1, j1;
    for(i1 = 0; i1 < j; i1++)
    {
        for(j1 = 0; j1 < i; j1++)
        {
            if(a[j1][i1] == 1)
                break;
            if(a[i-1][i1] == 0)
                return i1;
        }
    }
    return -1;
}

int main()
{
	int a[50][50];
    int tc,t;
    scanf("%d",&t);
    for(tc = 1; tc <= t; tc++)
    {
    	int rows, columns;
        scanf("%d%d",&rows,&columns);

        int i,j;
        for(i = 0; i < rows; i++)
        {
        	for(j = 0; j < columns; j++)
        	{
        		scanf("%d",&a[i][j]);
			}
		}
        int c = 0;

        for(i = 0; i < rows; i++)
        {
            for(j = 0; j < columns; j++)
            {
                if(a[i][j] == 1)
                    break;
                if(a[i][columns-1] == 0)
                {
                    int return1 = checkcolumns(a,rows,columns);
                    if(return1 != -1)
                    {
                        a[i][return1] = 1;
                        c += 1;
                    }
                }
            }
        }
        if(c%2 == 0)
            printf("\"Vivek\"\n");
        else
            printf("\"Ashish\"\n");
    }
}


#include <stdio.h>

int checkcolumns(int a[50][50], int i, int j)
{
	int i1, j1;
    for(i1 = 0; i1 < j; i1++)
    {
        for(j1 = 0; j1 < i; j1++)
        {
            if(a[j1][i1] == 1)
                break;
            if(a[i-1][i1] == 0)
                return i1;
        }
    }
    return -1;
}

int main()
{
	int a[50][50];
    int tc,t;
    scanf("%d",&t);
    for(tc = 1; tc <= t; tc++)
    {
    	int rows, columns;
        scanf("%d%d",&rows,&columns);

        int i,j;
        for(i = 0; i < rows; i++)
        {
        	for(j = 0; j < columns; j++)
        	{
        		scanf("%d",&a[i][j]);
			}
		}
        int c = 0, r = 0;

        for(i = 0; i < rows; i++)
        {
            for(j = 0; j < columns; j++)
            {
                if(a[i][j] == 1)
                    break;
                if(a[i][j] == 0)
                    r += 1;
                if(r == columns)
                {
                    int return1 = checkcolumns(a,rows,columns);
                    if(return1 != -1)
                    {
                        a[i][return1] = 1;
                        c += 1;
                    }
                }
            }
        }
        if(c%2 == 0)
            printf("\"Vivek\"\n");
        else
            printf("\"Ashish\"\n");
    }
}


#include <stdio.h>

int checkcolumns(int a[50][50], int i, int j)
{
	int i1, j1;
    for(i1 = 0; i1 < j; i1++)
    {
    	int cc = 0;
        for(j1 = 0; j1 < i; j1++)
        {
            if(a[j1][i1] == 1)
                break;
            if(a[j1][i1] == 0)
            	cc += 1;
            if(cc == i)
                return i1;
        }
    }
    return -1;
}

int main()
{
	int a[50][50];
    int tc,t;
    scanf("%d",&t);
    for(tc = 1; tc <= t; tc++)
    {
    	int rows, columns;
        scanf("%d%d",&rows,&columns);

        int i,j;
        for(i = 0; i < rows; i++)
        {
        	for(j = 0; j < columns; j++)
        	{
        		scanf("%d",&a[i][j]);
			}
		}
        int c = 0;

        for(i = 0; i < rows; i++)
        {
        	int r = 0;
            for(j = 0; j < columns; j++)
            {
                if(a[i][j] == 1)
                    break;
                if(a[i][j] == 0)
                    r += 1;
                if(r == columns)
                {
                    int return1 = checkcolumns(a,rows,columns);
                    if(return1 != -1)
                    {
                        a[i][return1] = 1;
                        c += 1;
                    }
                }
            }
        }
        if(c%2 == 0)
            printf("Vivek\n");
        else
            printf("Ashish\n");
    }
}


#include <stdio.h>

int checkcolumns(int a[50][50], int i, int j)
{
	int i1, j1;
    for(i1 = 0; i1 < j; i1++)
    {
        for(j1 = 0; j1 < i; j1++)
        {
            if(a[j1][i1] == 1)
                break;
            if(a[i-1][i1] == 0)
                return i1;
        }
    }
    return -1;
}

int main()
{
	int a[50][50];
    int tc,t;
    scanf("%d",&t);
    for(tc = 1; tc <= t; tc++)
    {
    	int rows, columns;
        scanf("%d%d",&rows,&columns);

        int i,j;
        for(i = 0; i < rows; i++)
        {
        	for(j = 0; j < columns; j++)
        	{
        		scanf("%d",&a[i][j]);
			}
		}
        int c = 0;

        for(i = 0; i < rows; i++)
        {
            for(j = 0; j < columns; j++)
            {
                if(a[i][j] == 1)
                    break;
                if(a[i][columns-1] == 0)
                {
                    int return1 = checkcolumns(a,rows,columns);
                    if(return1 != -1)
                    {
                        a[i][return1] = 1;
                        c += 1;
                    }
                }
            }
        }
        if(c%2 == 0)
            printf("Vivek\n");
        else
            printf("Ashish\n");
    }
}


#include<stdio.h>
char* input(int (*matrix)[50],int row,int col,int *r,int *c)
{
	for(int i=0;i<row;i++){
			for(int j=0;j<col;j++){
				scanf("%d",&matrix[i][j]);
				if(matrix[i][j]){
					r[i]=1;
					c[j]=1;

				}
			}
	}
	int r_count=0,c_count=0;
	for(int i=0;i<row;i++)
		r_count+=r[i];
	for(int i=0;i<col;i++)
		c_count+=c[i];
	int player;
	player=(row-r_count)>(col-c_count)?(col-c_count):(row-r_count);
	if (player%2)
		return "Ashish";
	else
		return "Vivek";

}
void main()
{
	int testcase,matrix[50][50];
	scanf("%d",&testcase);
	while(testcase--){
		int row,col;
		scanf("%d%d",&row,&col);
		//printf("%d %d\n",row,col);
		int r[row],c[col];
		for (int i=0;i<row;i++)
			r[i]=0;
		for (int i=0;i<col;i++)
			c[i]=0;
		char *player=input(matrix,row,col,r,c);
		printf("%s\n",player);

	}

}


#include<stdio.h>

void main()
{
	int testcase,matrix[50][50];
	scanf("%d",&testcase);
	while(testcase--){
		int row,col;
		scanf("%d%d",&row,&col);
		int r[row],c[col];
		for (int i=0;i<row;i++){
			for(int j=0;j<col;j++){
				scanf("%d",&matrix[i][j]);
				if (matrix[i][j])
					r[i]=c[j]=1;
			}

		}
		int r_count=0,c_count=0;
		for(int i=0;i<row;i++)
			r_count+=r[i];
		for(int i=0;i<col;i++)
			c_count+=c[i];
		int player=0;
		if (row-r_count>col-c_count)
			player=col-c_count;
		else
			player=row-r_count;
		if(player%2)
			printf("Ashish\n");
		else
			printf("Vivek\n");

	}

}


#include<stdio.h>
char* input(int (*matrix)[50],int row,int col,int *r,int *c)
{
	for(int i=0;i<row;i++){
			for(int j=0;j<col;j++){
				scanf("%d",&matrix[i][j]);
				if(matrix[i][j]){
					r[i]=1;
					c[j]=1;

				}
			}
	}
	int r_count=0,c_count=0;
	for(int i=0;i<row;i++)
		r_count+=r[i];
	for(int i=0;i<col;i++)
		c_count+=c[i];
	int player;
	player=(row-r_count)>(col-c_count)?(col-c_count):(row-r_count);
	if (player%2)
			return "Ashish";
	else
			return "Vivek";

}
void main()
{
	int testcase,matrix[50][50];
	scanf("%d",&testcase);
	while(testcase--){
		int row,col;
		scanf("%d%d",&row,&col);
		//printf("%d %d\n",row,col);
		int r[row],c[col];
		for (int i=0;i<row;i++)
			r[i]=0;
		for (int i=0;i<col;i++)
			c[i]=0;
		char *player=input(matrix,row,col,r,c);
		printf("%s\n",player);

	}

}


#include<stdio.h>
void main()
{
	int testcase,matrix[50][50];
	scanf("%d",&testcase);
	while(testcase--){
		int row,col;
		scanf("%d%d",&row,&col);
		int r[row],c[col];
		for (int i=0;i<row;i++)
			r[i]=0;
		for (int i=0;i<col;i++)
			c[i]=0;
		for (int i=0;i<row;i++){
			for(int j=0;j<col;j++){
				scanf("%d",&matrix[i][j]);
				if (matrix[i][j])
					r[i]=c[j]=1;
			}

		}
		int r_count=0,c_count=0;
		for(int i=0;i<row;i++)
			r_count+=r[i];
		for(int i=0;i<col;i++)
			c_count+=c[i];
		int player=0;
		if (row-r_count>col-c_count)
			player=col-c_count;
		else
			player=row-r_count;
		if(player%2)
			printf("Ashish\n");
		else
			printf("Vivek\n");

	}

}


//Matrix game (incomplete)
#include<stdio.h>
int main()
{
    int t,n,m,s,x,ans,i,j,a[51][51];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        s=0;
        x=0;
        ans=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(a[i][j]==1)
                {
                    s++;
                    break;
                }
            }
        }
        for(j=0;j<m;j++)
        {
            for(i=0;i<n;i++)
            {
                if(a[i][j]==1)
                {
                    x++;
                    break;
                }
            }
        }
        if(n-s>=m-x)
            ans=m-x;
        else
            ans=n-s;
        if(ans%2==0)
            printf("Vivek\n");
        else
            printf("Ashish\n");
    }
    return 0;
}


//Xenia and Ring road
#include<stdio.h>
int main()
{
    long long int n,m,sum=0,a[100005],i;
    scanf("%lld%lld",&n,&m);
    for(i=0;i<m;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<m;i++)
    {
        if(i==0)
        {
            sum=a[i]-1;
        }
        else
        {
            if(a[i]>=a[i-1])
                sum=sum+a[i]-a[i-1];
            else
                sum=sum+n-a[i-1]+a[i];
        }
    }
    printf("%lld",sum);
    return 0;
}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
    int n , m ,i,j ,x=0;
    scanf("%d%d",&n,&m);
    int a[n][m] ;
    for(i=0 ; i<n ; i++){
        for(j=0 ; j<m ; j++){
            scanf("%d",&a[i][j]);
            if (a[i][j]==0)x++ ;
        }
    }
    if(x%2==0){
        printf("Vivek\n");
    }
    else{
        printf("Ashish\n");
    }
    }
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int min(int x, int y)
{
	if(x>y)
	{
		return y;
	}

	return x;
}

int main()
{
	// variable in description
	int T;
	int N;
	int M;
	// variable to support
	int used_N[51];
	int used_M[51];
	int empty_N;
	int empty_M;
	int dummy;
	// variable to judge
	int i;
	int j;
	int k;

	scanf("%d",&T);

	for(i=0;i<T;i++)
	{
		scanf("%d %d",&N,&M);

		for(j=0;j<51;j++)
		{
			used_N[j] = 0;
			used_M[j] = 0;
		}

		for(j=0;j<N;j++)
		{
			for(k=0;k<M;k++)
			{
				scanf("%d",&dummy);
				if(dummy)
				{
					used_N[j] = 1;
					used_M[k] = 1;
				}
			}
		}

		empty_N = N;
		empty_M = M;

		for(j=0;j<N;j++)
		{
			empty_N -= used_N[j];
		}
		for(j=0;j<M;j++)
		{
			empty_M -= used_M[j];
		}

		if(min(empty_N,empty_M) % 2)
		{
			printf("Ashish\n");
		}
		else
		{
			printf("Vivek\n");
		}
	}

	return 0;
}


#include<stdio.h>
int main()
{
	int n, m, a, t, i, k, s, c;

	scanf("%d", &t);

	while(t--)
	{
		scanf("%d %d", &n, &m);
		c=0;

		for(i=0; i<n; i++)
		{
			s=0;
			for(k=0; k<m; k++)
			{
				scanf("%d", &a);
				s+=a;
			}
			if(s==0){
				c++;
			}
		}
		if(c%2==0)
		{
			printf("Vivek\n");
		}
		else
		{
			printf("Ashish\n");
		}
	}
	return 0;
}


#include <stdio.h>
#define fort(x, y, z) for (int x=y; x<z; x++)
#define fore(x, y, z) for (int x=y; x>=z; x--)

int max(int a, int b){
    if (a>=b) return a;
    return b;
}
int min(int a, int b){
    if (a<=b) return a;
    return b;
}
int main(){

    int t, n, m, matr[50][50], claimColumn[50], claimRow[50];

    scanf("%d", &t);

    while (t--){
        int f=0;
        scanf("%d%d", &n, &m);

        for (int i=0; i<n; i++) claimRow[i]=0;
        for (int j=0; j<m; j++) claimColumn[j]=0;

        for (int i=0; i<n; i++){
            for (int j=0; j<m; j++){
                scanf("%d", &matr[i][j]);
                if (matr[i][j]==1) claimRow[i]=1;
            }
        }
        for (int j=0; j<m; j++){
            for (int i=0; i<n; i++){
                if (matr[i][j]==1){
                    claimColumn[j]=1;
                    break;
                }
            }
        }
        for (int i=0; i<n; i++){
            if (claimRow[i]==1) continue;

            for (int j=0; j<m; j++){
                if (claimColumn[j]==1) continue;

                claimColumn[j]=1;
                f++;
                f%=2;
                break;
            }
        }
        if (f==0) printf("Vivek\n");
        else printf("Ashish\n");
    }
}


#include <stdio.h>
#define fort(x, y, z) for (int x=y; x<z; x++)
#define fore(x, y, z) for (int x=y; x>=z; x--)

int max(int a, int b){
    if (a>=b) return a;
    return b;
}
int min(int a, int b){
    if (a<=b) return a;
    return b;
}
int main(){

    int t, n, m, matr[50][50], claimColumn[50], claimRow[50];

    scanf("%d", &t);

    while (t--){
        int f=0;
        scanf("%d%d", &n, &m);

        for (int i=0; i<n; i++) claimRow[i]=0;
        for (int j=0; j<m; j++) claimColumn[j]=0;

        for (int i=0; i<n; i++){
            for (int j=0; j<m; j++){
                scanf("%d", &matr[i][j]);
                if (matr[i][j]==1) claimRow[i]=1;
            }
        }
        for (int j=0; j<m; j++){
            for (int i=0; j<n; j++){
                if (matr[i][j]==1){
                    claimColumn[j]=1;
                    break;
                }
            }
        }
        for (int i=0; i<n; i++){
            if (claimRow[i]==1) continue;

            for (int j=0; j<m; j++){
                if (claimColumn[j]==1) continue;

                claimColumn[j]=1;
                f++;
                f%=2;
                break;
            }
        }
        if (f==0) printf("Vivek\n");
        else printf("Ashish\n");
    }
}


#include <stdio.h>
#define fort(x, y, z) for (int x=y; x<z; x++)
#define fore(x, y, z) for (int x=y; x>=z; x--)

int max(int a, int b){
    if (a>=b) return a;
    return b;
}
int min(int a, int b){
    if (a<=b) return a;
    return b;
}
int main(){

    int t, n, m, matr[50][50], claimColumn[50], claimRow[50];

    scanf("%d", &t);

    while (t--){
        int f=0;
        scanf("%d%d", &n, &m);

        for (int i=0; i<n; i++){
            for (int j=0; j<m; j++){
                scanf("%d", &matr[i][j]);
                if (matr[i][j]==1) claimRow[i]=1;
            }
        }
        for (int j=0; j<m; j++){
            for (int i=0; j<n; j++){
                if (matr[i][j]==1){
                    claimColumn[j]=1;
                    break;
                }
            }
        }
        for (int i=0; i<n; i++){
            if (claimRow[i]==1) continue;

            for (int j=0; j<m; j++){
                if (claimColumn[j]==1) continue;

                claimColumn[j]=1;
                f++;
                f%=2;
            }
        }
        if (f==0) printf("Vivek\n");
        else printf("Ashish\n");
    }
}


#include<stdio.h>
#include<string.h>
#define limit  1000
int main()
{
    long long int t;
    scanf("%lld",&t);
    long long int n,m,i,x,y,a[51][51],cn=0,cm=0,count=0;
    for(i=0;i<t;i++)
    {
        cn=0;
        cm=0;
        scanf("%lld %lld",&n,&m);
        for(x=0;x<n;x++)
        {
            count=0;
            for(y=0;y<m;y++)
            {
                scanf("%lld",&a[x][y]);
                if(a[x][y]==0)
                count++;
            }
            if(count==m)
            cn++;
        }
        for(y=0;y<m;y++)
        {
            count=0;
            for(x=0;x<n;x++)
            {
                if(a[x][y]==0)
                count++;
            }
            if(count==n)
            cm++;
        }
        if(cn<=cm)
        {
            if(cn%2==0)
            printf("Vivek\n");
            else
            printf("Ashish\n");
        }
        if(cm<cn)
        {
          if(cm%2==0)
            printf("Vivek\n");
            else
            printf("Ashish\n");
        }
    }
    return 0;
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	int n,m;
	scanf("%d %d",&n,&m);
	int a[n+1][m+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
	    scanf("%d",&a[i][j]);
	}
	int x,y;
	int p,q;
	int count=0;
	for(int i=1;i<=n;i++)
	{
		x=i;

		for(int j=1;j<=m;j++)
		{
			y=j;
			if(a[x][j]==0)
			{
				x=1;
				p=0,q=0;
				while(x<(n+1))
				{
					if(a[x][j]==1)
					{
						p++;
						break;
					}
					x++;
				}
				if(p==0)
				{
					j=1;
					while(j<(m+1))
					{
						if(a[i][j]==1)
						{
							q++;
							break;
						}
						j++;
					}
					if(q==0)
				{
					count++;
					//printf("count %d",count);
				}
				}

			}

			j=y;
		}

	}
	if(count == 0 || count%2==0)
	printf("Vivek\n");
	else
	printf("Ashish\n");

	}
	return 0;
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	int n,m;
	scanf("%d %d",&n,&m);
	int a[n+1][m+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
	    scanf("%d",&a[i][j]);
	}
	int x,y;
	int p,q;
	int count=0;
	for(int i=1;i<=n;i++)
	{
		x=i;

		for(int j=1;j<=m;j++)
		{
			y=j;
			if(a[x][j]==0)
			{
				x=1;
				p=0,q=0;
				while(x<(n+1))
				{
					if(a[x][j]==1)
					{
						p++;
						break;
					}
					x++;
				}
				if(p==0)
				{
					j=1;
					while(j<(m+1))
					{
						if(a[i][j]==1)
						{
							q++;
							break;
						}
						j++;
					}
					if(q==0)
				     {
					       count++;
					       //printf("count %d",count);
					       a[i][y]=1;

				     }
				}

			}

			j=y;
		}

	}
	if(count == 0 || count%2==0)
	printf("Vivek\n");
	else
	printf("Ashish\n");

	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int t;
    scanf ("%i", &t);

    for (int k = 0; k < t; k++)
    {
        int n, m;
        scanf ("%i %i", &n, &m);

        int **grid = malloc (sizeof (int *) * n);
        for (int i = 0; i < n; i++)
        {
            grid[i] = malloc (sizeof (int) * m);
            for (int j = 0; j < m; j++)
                scanf ("%i", (grid[i] + j));
        }

        int *rows = calloc (n, sizeof (int));
        int *cols = calloc (m, sizeof (int));

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (!grid[i][j])
                    continue;
                rows[i] = 1;
                cols[j] = 1;
            }
        }

        int nrows = 0, ncols = 0;
        for (int i = 0; i < n; i++)
            if (!rows[i])
                nrows++;
        for (int j = 0; j < m; j++)
            if (!cols[j])
                ncols++;

        int min = (nrows < ncols) ? nrows : ncols;
        char *winner = (min % 2 == 0) ? "Vivek" : "Ashish";
        printf ("%s\n", winner);

        free (rows);
        free (cols);

        for (int i = 0; i < n; i++)
            free (grid[i]);
        free (grid);
    }
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int row[50],col[50];
void ara()
{
    int i;
    for(i=0;i<50;i++)row[i]=col[i]=0;
}
int comparefunc (const void * a, const void * b)
{
    return (*(int*)b)-(*(int*)a);
}
int main()
{
    //printf("%d %d", a['a']);
    int i,j,k,m,n,t;
    scanf("%d", &t);
    for(i=0;i<t;i++){
        scanf("%d%d", &n,&m);
        int a[n][m],ans=0;
        ara();
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                scanf("%d", &a[j][k]);
                if(a[j][k]==1){
                    row[j]=1;
                    col[k]=1;
                }
            }
        }
        for(j=0;j<k;j++){
            for(k=0;k<m;k++){
                if(row[j]==0&&col[k]==0){
                    ans++;
                    row[j]=1;
                    col[k]=1;
                }
            }
        }
        if(ans%2==0)printf("Vivek\n");
        else printf("Ashish\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int row[50],col[50];
void ara()
{
    int i;
    for(i=0;i<50;i++)row[i]=col[i]=0;
}
int comparefunc (const void * a, const void * b)
{
    return (*(int*)b)-(*(int*)a);
}
int main()
{
    //printf("%d %d", a['a']);
    int i,j,k,m,n,t;
    scanf("%d", &t);
    for(i=0;i<t;i++){
        scanf("%d%d", &n,&m);
        int a[n][m],ans=0;
        ara();
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                scanf("%d", &a[j][k]);
                if(a[j][k]==1){
                    row[j]=1;
                    col[k]=1;
                }
            }
        }
        for(j=0;j<k;j++){
            for(k=0;k<m;k++){
                if(row[j]==0&&col[k]==0){
                    ans++;
                    row[j]=1;
                    row[k]=1;
                }
            }
        }
        if(ans%2==0)printf("Vivek\n");
        else printf("Ashish\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int row[50],col[50];
void ara()
{
    int i;
    for(i=0;i<50;i++)row[i]=col[i]=0;
}
int comparefunc (const void * a, const void * b)
{
    return (*(int*)b)-(*(int*)a);
}
int main()
{
    //printf("%d %d", a['a']);
    int i,j,k,m,n,t;
    scanf("%d", &t);
    for(i=0;i<t;i++){
        scanf("%d%d", &n,&m);
        int a[n][m],ans=0;
        ara();
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                scanf("%d", &a[j][k]);
                if(a[j][k]==1){
                    row[j]=1;
                    col[k]=1;
                }
            }
        }
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                if(row[j]==0&&col[k]==0){
                    ans++;
                    row[j]=1;
                    col[k]=1;
                }
            }
        }
        if(ans%2==0)printf("Vivek\n");
        else printf("Ashish\n");
    }
    return 0;
}


#include <stdlib.h>

#define MAX_NUM_ROWS 50
#define MAX_NUM_COLS 50

typedef struct Matrix {
    int m, n;
    int rows[MAX_NUM_ROWS];
    int cols[MAX_NUM_COLS];
} Matrix;

void clear_matrix(Matrix* A) {
    for (int i = 0; i < MAX_NUM_ROWS; i++) {
        A->rows[i] = 0;
    }
    for (int j = 0; j < MAX_NUM_COLS; j++) {
        A->cols[j] = 0;
    }
}

void read_matrix(Matrix* A) {
    scanf("%d %d", &A->m, &A->n);
    for (int i = 0; i < A->m; i++) {
        for (int j = 0; j < A->n; j++) {
            int x;
            scanf("%d", &x);
            // Don't care if redundant assignment
            A->rows[i] |= x;
            A->cols[j] |= x;
        }
    }
}

void print_matrix(Matrix* A) {
    printf("Row marker array: \n");
    for (int i = 0; i < A->m; i++) {
        printf("%d ", A->rows[i]);
    }
    printf("\n");
    printf("Column marker array: \n");
    for (int j = 0; j < A->n; j++) {
        printf("%d ", A->cols[j]);
        printf("%d ", A->cols[j]);
    }
    printf("\n");
}

char* game_winner(Matrix* A) {
    static char* name[2] = {"Ashish", "Vivek"};
    // Assuming Ashish always goes first
    int turn = 1; // 1 if Ashish's turn, 0 if Vivek's
    while (1) {
        int found_row = 0;
        for (int i = 0; i < A->m; i++) {
            // Find the first available row
            if (!A->rows[i]) {
                A->rows[i] = 1;
                found_row = 1;
                break;
            }
        }
        if (!found_row) {
            return name[turn];
        }

        int found_col = 0;
        for (int j = 0; j < A->n; j++) {
            // Find the first available row
            if (!A->cols[j]) {
                A->cols[j] = 1;
                found_col = 1;
                break;
            }
        }
        if (!found_col) {
            return name[turn];
        }
        turn ^= 1;
    }
}

int main() {
    int num_matrices;
    scanf("%d", &num_matrices);
    Matrix matrix;

    for (int i = 0; i < num_matrices; i++) {
        clear_matrix(&matrix);
        read_matrix(&matrix);
        // print_matrix(&matrix);
        char* answer = game_winner(&matrix);
        printf("%s\n", answer);
    }
}


#include<stdio.h>
int main()
{
    int i,j,k,m,n,c,p,l,t;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {   c=0;
        scanf("%d%d",&n,&m);
        int ara[n][m];
        for(j=0;j<n;j++)
        {
            for(k=0;k<m;k++)
            {
                scanf("%d",&ara[j][k]);
            }
        }
        for(j=0;j<n;j++)
        {
            for(k=0;k<m;k++)
            {
                if(ara[j][k]==1)
                {
                    c++;
                }
            }
        }

        p=n-c;
        if(p<0)
        {
            printf("Vivek\n");
        }
        else
        {
            if(p%2==0)
            {
                printf("Vivek\n");
            }
            else
            {
                printf("Ashish\n");
            }
        }

    }
    return 0;
}


#include<stdio.h>

int main()
{int d,n,m,count,t,i,j,k,p,count2;
float c;
scanf("%d",&t);
for(i=0;i<t;i++)
 { scanf("%d %d",&n,&m);
   int ara[n][m];
   count=0;
   for(j=0;j<n;j++)
     { for(k=0;k<m;k++)
         { scanf("%d",&p);
           ara[j][k]=p;
           if((p==1)&&((k==j)||(abs(k-j)==2)))
             { count++;}
         }
     }
   c=((float)m*(float)n)/2.0;
   if((c-(int)c)==0)
      { d=(int)c;}
   else
      { d=(int)c+1;}
   count2=count-d;
   count2=(-1)*count2;
   if(count2%2==0){ printf("Vivek\n");}
   else { printf("Ashish\n");}
 }
    return 0;
}


#include<stdio.h>

int main()
{int d,n,m,count,t,i,j,k,p,count2;
float c;
scanf("%d",&t);
for(i=0;i<t;i++)
 { scanf("%d %d",&n,&m);
   int ara[n][m];
   count=0;
   for(j=0;j<n;j++)
     { for(k=0;k<m;k++)
         { scanf("%d",&p);
           ara[j][k]=p;
           if((p==1)&&((k==j)||(abs(k-j)==2)))
             { count++;}
         }
     }
   c=((float)m*(float)n)/2.0;
   if((c-(int)c)==0)
      { d=(int)c;}
   else
      { d=(int)c+1;}
   count2=count-d;
   count2=(-1)*count2;

   if(count2%2==0)
      { printf("Vivek\n");}
   else if((count%2!=0)&&(count2!=1))
      { printf("Ashish\n");}
   else
      { printf("Vivek\n");}
  // printf("%d",count2);

 }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
int main ()
{
    int t , i , n , m ,  j ;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        int arr[n][m];
        int nn=0 , mm=0;
        for(i=0 ; i < n ;i++)
        {
            for(j=0 ; j<m ; j++)
            {
                 scanf("%d",&arr[i][j]);
                 if(arr[i][j]==1)
                 {
                     ++nn;
                     ++mm;
                  }
            }
        }
        int rem=MIN(abs(n-nn),abs(m-mm));
        //printf("%d %d\n",nn,rem);
        if(rem%2!=0) puts("Ashish");
        else if(rem%2==0) puts("Vivek");
    }
    return 0;
}


#include<stdio.h>
int main()
{
	int t,n,m,i,j,arr[50][50],nn,flag,mm;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++)scanf("%d",&arr[i][j]);
		}
		nn=0;
		mm=0;
		for(i=0;i<n;i++){
			flag=1;
			for(j=0;j<m;j++){
				if(arr[i][j])flag=0;
			}
			if(flag)nn++;
		}
		for(j=0;j<m;j++){
			flag=1;
			for(i=0;i<n;i++){
				if(arr[i][j])flag=0;
			}
			if(flag)mm++;
		}
		if(nn>mm)flag=mm;
		else flag=nn;
		if(flag%2)printf("Ashish\n");
		else printf("Vivek\n");
	}
        return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) (a)<(b)?(a):(b)
int main ()
{
    int t , i , n , m ,  j ;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        int arr[n][m];
        int nn=0 , mm=0;
        for(i=0 ; i < n ;i++)
        {
            for(j=0 ; j<m ; j++)
            {
                 scanf("%d",&arr[i][j]);
                 if(arr[i][j]==1)
                 {
                     ++nn;
                     ++mm;
                  }
            }
        }
        int rem=MIN(n-abs(nn),n-abs(mm));
        //printf("%d %d\n",nn,rem);
        if(rem%2!=0) puts("Ashish");
        else if(rem%2==0) puts("Vivek");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#define MIN(a,b) a<b?a:b
int main ()
{
    int t , i , n , m ,  j ;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        int arr[n][m];
        int nn=0 , mm=0;
        for(i=0 ; i < n ;i++)
        {
            for(j=0 ; j<m ; j++)
            {
                 scanf("%d",&arr[i][j]);
                 if(arr[i][j]==1)
                 {
                     ++nn;
                     ++mm;
                  }
            }
        }
        int rem=MIN(n-nn,m-mm);
        if(rem%2!=0) puts("Ashish");
        else if(rem%2==0) puts("Vivek");
    }
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
int main ()
{
    int t , i , n , m ,  j ;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        int arr[n][m];
        int nn=0 , mm=0;
        for(i=0 ; i < n ;i++)
        {
            for(j=0 ; j<m ; j++)
            {
                 scanf("%d",&arr[i][j]);
                 if(arr[i][j]==1)
                 {
                     ++nn;
                     ++mm;
                  }
            }
        }
        int rem=MIN(abs(n-nn),abs(m-mm));
        printf("%d %d\n",nn,rem);
        if(rem%2!=0) puts("Ashish");
        else if(rem%2==0) puts("Vivek");
    }
    return 0;
}