#include<cstdio>
#include<cctype>
using namespace std;
int father[10001],ask1,ask2;
int maxn,maxm,symbol;
inline void read(int &number){
number=0;
int minus=1;
char got=getchar();
while(!isdigit(got)){
if(got=='-'){
minus=-1;
};
got=getchar();
};
while(isdigit(got)){
number=number*10+got-'0';
got=getchar();
};
number*=minus;
};
int find(int found){
while(father[found]!=found){
found=father[found];
};
return found;
};
void make(const int root,const int add){
father[root]=add;
};
int main(){
read(maxn),read(maxm);
for(int it=1;it<=maxn;it++){
father[it]=it;
};
while(maxm--){
read(symbol),read(ask1),read(ask2);
if(symbol==1){
make(ask1,ask2);
}else{
if(find(ask1)==find(ask2)){
puts("Y");
}else{
puts("N");
};
};
};
return 0;
};