#include<bits/stdc++.h>
using namespace std;
int n,q,f[10001];
int get(int x){
if(f[x]==x) return x;
return get(f[x]);
}
int main(){
cin >> n >> q;
for(int i=1;i<=n;i++) f[i]=i;
while(q--){
int x,y,z;
cin >> z >> x >> y;
if(z==1){
if(get(x)!=get(y)) f[y]=x;
}else{
if(get(x)==get(y)) cout << "Y" << endl;
else cout << "N" << endl;
}
}
return 0;
}