#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int p[N];
int n,m;
int find(int x){
if(p[x]!=x)p[x] = find(p[x]);
return p[x];
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;i++)p[i] = i;
while(m--){
char t;
cin>>t;
int a,b;
scanf("%d%d",&a,&b);
a = find(a);b = find(b);
if(t=='M'){
p[a] = b;
}
else{
if(a==b)printf("Yes\n");
else printf("No\n");
}
}
}