#include<bits/stdc++.h>
using namespace std;
int n,m;
int f[10005];
int find(int x)
{
if(f[x]!=x) f[x]=find(f[x]);
return f[x];
}
int hebin(int x,int y)
{
f[y]=x;
}
main()
{
cin>>n>>m;
int x,y,z,x1,y1;
for(int i=1;i<=n;i++)
f[i]=i;
for(int i=1;i<=m;i++)
{
cin>>z>>x>>y;
int x1=find(x);
int y1=find(y);
if(z==1)
{
if(x1!=y1) hebin(x1,y1);
}
if(z==2)
{
if(x1!=y1) cout<<"N"<<endl;
else cout<<"Y"<<endl;
}
}
system("pause");
return 0;
}