#include<bits/stdc++.h> using namespace std; int fa[10005]; int m,n; int find(int x){ if(fa[x]!=x){ fa[x]=find(fa[x]); } return fa[x]; } bool judge(int x,int y){ x=find(x); y=find(y); if(x==y){ return 1; } else{ return 0; } } void combin(int x,int y){ x=find(x); y=find(y); fa[y]=x; } int main() { cin>>n>>m; for(int i=1;i<=n;i++){ fa[i]=i; } for(int i=1;i<=m;i++){ int k; cin>>k; int x,y; cin>>x>>y; if(k==1){ combin(x,y); } else{ if(judge(x,y)){ cout<<"Y"<<endl; } else{ cout<<"N"<<endl; } } } return 0; }