import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
* @author lubin
/
public class Main {
static final int N=100010;
static int[] p = new int[N];
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] s=bufferedReader.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
for (int i=1;i<=n;i++) p[i]=i;
while (m-->0){
String[] s1 = bufferedReader.readLine().split(" ");
if (s1[0].equals("M")) p[find(Integer.parseInt(s1[1]))]=find(Integer.parseInt(s1[2]));
else {
if (find(Integer.parseInt(s1[1]))==find(Integer.parseInt(s1[2]))) System.out.println("Yes");
else System.out.println("No");
}
}
}
static int find(int x){
if (p[x]!=x) p[x]=find(p[x]);//p[x]==x时,代表x是祖宗结点,p[x]存储 的是x结点的祖宗节点
return p[x];
}
}