#include<iostream>
#include<algorithm>
using namespace std;const int N=1e5+10;
int st[N];
int n,m;
int find(int x){if(st[x]!=x)
st[x]=find(st[x]);elsereturn st[x];}
int main(){
cin >> n >> m;for(int i=1;i<=n;i++)
st[i]=i;while(m--){
char op;
cin >> op;
int a,b;
cin >> a >> b;if(op=='M'){//采用的是树的双亲表示法存储的//数组中存储的是双亲的下标
st[find(a)]=find(b);}elseif(op=='Q'){if(find(a)==find(b))
cout <<"Yes"<< endl;else
cout <<"No"<< endl;}}return0;}