#include <iostream>
using namespace std;
int g[200005], n, m;
int find(int x)//找根节点
{
if (g[x]!=x)
{
g[x] = find(g[x]);//爸爸的爸爸叫什么
}
return g[x];
}
int main()
{
cin>>n>>m;
for (int i = 1;i<=n;i++)//我是我的爹
{
g[i] = i;
}
for (int i = 1;i<=m;i++)//我是谁的爹?
{
int z, x, y;
cin>>z>>x>>y;
int fx = find(x), fy = find(y);
if (z==1)
{
g[fx] = fy;
}
else
{
if (fx==fy) cout<<"Y\n";
else cout<<"N\n";
}
}
return 0;
}