def find(value):#返回X的祖宗节点加路径压缩
if(q[value]!=value):
q[value]=find(q[value])
return q[value]
if __name__=="__main__":
n,m=map(int,input().split())
q=[0]*(n+10)
for i in range(n):
q[i]=i
while m:
ask=list(map(str,input().split()))
if ask[0]=="M":
a=int(ask[1])
b=int(ask[2])
q[find(a)]=find(b)
else:
if find(int(ask[1]))==find(int(ask[2])):
print("Yes")
else:
print("No")
m-=1