#include template inline void read(T& t) { t=0; bool f=false; char ch; while(ch=getchar(),!((ch>='0'&&ch<='9')||ch=='-')); if(ch=='-') f=true,ch=getchar(); t=ch-'0'; while(ch=getchar(),ch>='0'&&ch<='9') t=t*10+ch-'0'; if(f) t=-t; } template inline void read(T& t,Args&... args) { read(t); read(args...); } const int maxn=10005; int n,m; int fa[maxn],dep[maxn]; inline int ff(int x) { int a=x,b; while(x!=fa[x]) x=fa[x]; while(a!=x) { b=fa[a]; fa[a]=x; a=b; } return x; } inline void Union(int x,int y) { int fx=ff(x),fy=ff(y); if(fx==fy) return; if(dep[fx]0) { read(opt,x,y); if(opt==1) Union(x,y); else puts(ff(x)==ff(y)?"Y":"N"); } return 0; }