#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define REG register
#define REP(i,x,y) for(register int i=x;i<=y;i++)
#define UP(i,x,y) for(register int i=x;i>=y;i--)
#define IN inline
int fa[10005];
int getf(int x){
if(x==fa[x]) return x;
return fa[x]=getf(fa[x]);
}
IN void merge(int p,int q){
fa[getf(p)]=getf(q);
}
IN void find(int x,int y){
if(getf(x)==getf(y)) printf("Y\n");
else printf("N\n");
}
int main(){
int m,n,x,y,z;
scanf("%d %d",&m,&n);
REP(i,1,m) fa[i]=i;
REP(i,1,n){
scanf("%d %d %d",&x,&y,&z);
if(x==1) merge(y,z);
else if(x==2) find(y,z);
}
return 0;
}