#include <bits/stdc++.h>
using namespace std;
long long f[1086],n,m,z;
long long a,b;
int find(int x)
{
return x==f[x]?x:find(f[x]);
}
void hebing (int x,int y)
{
int fx,fy;
fx=find(x);
fy=find(y);
f[fx]=fy;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
f[i]=i;
}
for(int i=1;i<=m;i++)
{
cin>>z>>a>>b;
if(z==1)
{
hebing(a,b);
}
if(z==2){
if(find(a)==find(b)){
cout<<"Y"<<endl;
}
else {
cout<<"N"<<endl;
}
}
}
return 0;
}