#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int fa[N];
int n, m;
int find(int x) {
if (fa[x] = x)
return x;
return fa[x] = find(fa[x]);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i ++)
fa[i] = i;
while (m --) {
int z, x, y;
cin >> z >> x >> y;
if (z == 1) {
fa[find(x)] = find(y);
} else {
if (find(x) == find(y))
cout << "Y" << endl;
else
cout << "N" << endl;
}
}
return 0;
}