#include<iostream>
using namespace std;
int a[100005];
int findb(int b)
{
if(a[b]!=b)a[b]=findb(a[b]);
return a[b];
}
int main()
{
int n,m,i,x,y;
char s[2];
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)a[i]=i;
while(m--){
scanf("%s%d%d",s,&x,&y);
if(s[0]=='M')a[findb(x)]=findb(y);
else{
if(findb(x)==findb(y))printf("Yes\n");
else printf("No\n");
}
}
return 0;
}