def find(x,p):
r=x
while r!=p[r]:
r=p[r]
while x!=r:
t=p[x]
p[x]=r
x=t
return r
if __name__=="__main__":
n,m =[int(x) for x in input().split()]
p = list(range(0,n+1))
for i in range(0,m):
opt,e1,e2 = input().split()
e1 = int(e1)
e2 = int(e2)
p1 = find(e1,p)
p2 = find(e2,p)
if opt == "M":
if p1!=p2:
p[p1]=p2
elif opt=="Q":
if p1 != p2:
print("No")
else:
print("Yes")