#include<bits/stdc++.h>
using namespace std;
long par[1000005];
long find_korlam(long a1)
{
if(par[a1]==a1)
return a1;
else
find_korlam(par[a1]);
}
main()
{
long ts,cs=1;
cin>>ts;
while(ts--)
{
long n,i;
cin>>n;
for(i=1;i<=n;i++)
par[i]=i;
char s;
long a,b,u,v,success=0,unsuccess=0;
getchar();
while((s=getchar())&&(isalpha(s)))
{
cin>>a>>b;
getchar();
u=find_korlam(a);
v=find_korlam(b);
if(s=='c')
{
if(u!=v)
par[u]=v;
}
else if(s=='q')
{
if(u==v)
{
success++;
}
else
unsuccess++;
}
else
break;
}
if(cs>1)
cout<<endl;
cs++;
cout<<success<<","<<unsuccess<<endl;
}
}
using namespace std;
long par[1000005];
long find_korlam(long a1)
{
if(par[a1]==a1)
return a1;
else
find_korlam(par[a1]);
}
main()
{
long ts,cs=1;
cin>>ts;
while(ts--)
{
long n,i;
cin>>n;
for(i=1;i<=n;i++)
par[i]=i;
char s;
long a,b,u,v,success=0,unsuccess=0;
getchar();
while((s=getchar())&&(isalpha(s)))
{
cin>>a>>b;
getchar();
u=find_korlam(a);
v=find_korlam(b);
if(s=='c')
{
if(u!=v)
par[u]=v;
}
else if(s=='q')
{
if(u==v)
{
success++;
}
else
unsuccess++;
}
else
break;
}
if(cs>1)
cout<<endl;
cs++;
cout<<success<<","<<unsuccess<<endl;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন