#include<bits/stdc++.h>
#define maxn 10005
using namespace std;
typedef long long ll;
ll n,m,z,x,y,A[10005];
ll fi(ll k) //找祖宗
{
return A[k]==k?k:A[k]=fi(A[k]);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<maxn;i++)
A[i]=i;
while(m--)
{
cin>>z>>x>>y;
if(z==1)
{
A[fi(x)]=fi(y);
}
else
{
if(fi(x)==fi(y))
cout<<"Y"<<endl;
else
cout<<"N"<<endl;
}
}
return 0;
}