#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,fa[100005],c=1,T,num[100005],ans;
inline void init(){
ans=n;
for(int i=1;i<=n;++i) fa[i]=i,num[i]=1;
}
inline int find(int x){
if(fa[x]==x) return x;
else return fa[x]=find(fa[x]);
}
inline int change(int x){
int t=0;
for(int i=1;i<=n;++i){
if(fa[i]=x&&i!=x){
if(!t)t=i;
else fa[i]=t;
}
}
return t;
}
int main(){
//freopen("game.in","w",stdin);
//freopen("game.out","r",stdout);
scanf("%d",&T);
while(T--){
printf("Case #%d\n",c);
scanf("%d%d",&n,&m);
init();
while(m--){
string s; int x,y;
cin>>s;
if(s=="query"){
printf("%d\n",ans);
}
if(s=="fight"){
scanf("%d%d",&x,&y);
int xx=find(x),yy=find(y);
if(xx==yy) continue;
else if(num[xx]<num[yy]){
printf("%d is winner\n",y);
fa[xx]=yy;
num[yy]+=num[xx];
num[xx]=0;
ans--;
}
else if(num[xx]>num[yy]){
printf("%d is winner!\n",x);
fa[yy]=xx;
num[xx]+=num[yy];
num[yy]=0;
ans--;
}
else printf("Either is winner!\n");
}
if(s=="tempt"){
scanf("%d%d",&x,&y);
int xx=find(x),yy=find(y);
if(y==yy){
if(num[yy]==1){
num[yy]--;
ans--;
fa[y]=xx;
num[xx]++;
}
else{
num[change(y)]=num[y]-1;
num[yy]=0;
fa[y]=xx;
num[xx]++;
}
}
else{
num[xx]++; num[yy]--;
fa[y]=xx;
}
}
if(s=="revolt"){
scanf("%d",&x);
int xx=find(x);
if(xx==x){
if(num[x]==1) continue;
else{
num[change(x)]=num[x]-1;
num[x]=1;
ans++;
}
}
num[xx]--;
fa[x]=x;
num[x]=1;
ans++;
}
}
}
}