#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=100010;
int p[N];
int find(int x)
{
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
}
signed main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
p[i]=i;
for(int i=1;i<=m;i++)
{
char c;
cin>>c;
int a,b;
cin>>a>>b;
if(c=='M')
{
if(find(a)!=find(b))
p[find(a)]=find(b);
}
else
{
if(find(a)==find(b))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}