#include <iostream>
using namespace std;
int fa[100005];
int n,m,k;
int fi(int x){
if(x==fa[x])return x;
return fi(fa[x]);
}
bool check(int x,int y){
int fx=fi(x),fy=fi(y);
return fx==fy;
}
void merge(int x,int y){
if(check(x,y))return ;
int fx=fi(x),fy=fi(y);
fa[fx]=fy;
}
int main(){
cin >>n >>m;
for(int i=1;i<=n;i++){
fa[i]=i;
}
for(int i=1;i<=m;i++){
int x,y,z;
cin >>x >>y >>z;
if(x==1){
merge(y,z);
}
else{
if(check(y,z))cout <<"Y\n";
else cout <<"N\n";
}
}
return 0;
}