#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n,m;
int fa[N];
int find(int x){
//三目运算符简化代码
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
cin>>n>>m;
for(int i = 1;i<=n;i++)fa[i]=i;
for(int i = 1;i<=m;i++){
char ch;
int a,b;
cin>>ch>>a>>b;
//合并操作,让b的根节点等于a的根节点
if(ch=='M')fa[find(b)]=find(a);
else{
//查询操作,比较a和b的根节点
if(find(a)==find(b))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return 0;
}