#include<bits/stdc++.h>
using namespace std;
int m,n,o,p,q;
struct node{
short pa=0;
}a[10004];
int find(int x){
if(a[x].pa==0){
return x;
}
else{
a[x].pa=find(a[x].pa);
return a[x].pa;
}
}
void he(int x,int y){
a[find(y)].pa=find(x);
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>o>>p>>q;
if(o==1)he(q,p);
else{
if(find(q)==find(p))cout<<"Y"<<endl;
else cout<<"N"<<endl;
}
}
return 0;
}