#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 300000
int n,m,x,y,top,fa[N],stk[N],rev[N],son[N][2];
char ch;
bool isroot(int x){return son[fa[x]][0]!=x && son[fa[x]][1]!=x;}
void pushdown(int x){if (rev[x]){swap(son[x][0],son[x][1]); rev[son[x][0]]^=1; rev[son[x][1]]^=1;} rev[x]=0;}
void rotate(int x,int w){
int y=fa[x];
son[y][w^1]=son[x][w]; if (son[x][w]) fa[son[x][w]]=y;
fa[x]=fa[y]; if (!isroot(y)){if (y==son[fa[y]][0]) son[fa[y]][0]=x; else son[fa[y]][1]=x;}
fa[y]=x; son[x][w]=y;
}
void splay(int x){
stk[++top]=x; for (int y=x;!isroot(y);y=fa[y]) stk[++top]=fa[y];
for (;top;top--) pushdown(stk[top]);
for (int y=fa[x];!isroot(x);y=fa[x]){
if (isroot(y)){if (x==son[y][0]) rotate(x,1); else rotate(x,0);}
else{
if (x==son[y][0]){if (y==son[fa[y]][0]){rotate(y,1); rotate(x,1);} else{rotate(x,1); rotate(x,0);}}
else{if (y==son[fa[y]][0]){rotate(x,0); rotate(x,1);} else{rotate(y,0); rotate(x,0);}}
}
}
}
void access(int x){for (int t=0;x;x=fa[x]){splay(x); son[x][1]=t; t=x;}}
void setroot(int x){access(x); splay(x); rev[x]^=1;}
void link(int x,int y){setroot(x); fa[x]=y;}
void cut(int x,int y){setroot(x); access(y); splay(y); fa[x]=son[y][0]=0;}
inline int find(int x){access(x); splay(x); for (;son[x][0];x=son[x][0]); return x;}
bool query(int x,int y){x=find(x); y=find(y); return x==y;}
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++){
char ch;
for (ch=getchar();ch!='Q' && ch!='C' && ch!='D';ch=getchar());
if (ch=='Q'){for (ch=getchar();ch>='a' && ch<='z';ch=getchar()); scanf("%d%d",&x,&y); puts(query(x,y)?"Yes":"No");}
if (ch=='C'){for (ch=getchar();ch>='a' && ch<='z';ch=getchar()); scanf("%d%d",&x,&y); link(x,y);}
if (ch=='D'){for (ch=getchar();ch>='a' && ch<='z';ch=getchar()); scanf("%d%d",&x,&y); cut(x,y);}
}
return 0;
}