#include<bits/stdc++.h>
using namespace std;
int a[10010],zhi[10010];
int fd(int x)
{
if(a[x]==x)
return x;
return a[x]=fd(x);
}
void hb(int x,int y)
{
int r1=fd(x),r2=fd(y);
if(x==y)
return ;
if(zhi[x]<zhi[y])
{
a[r1]=r2;
zhi[y]+=zhi[x];
return ;
}
a[r2]=r1;
zhi[x]+=zhi[y];
return ;
}
void judge(int x,int y)
{
if(a[x]==a[y])
cout<<"Y"<<endl;
else cout<<"N"<<endl;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
a[i]=i;
zhi[i]=1;
}
for(int i=1;i<=m;i++)
{
int z,x,y;
cin>>z>>x>>y;
if(z==1)
hb(x,y);
else
judge(x,y);
}
return 0;
}