#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[10001];
int find(int x) {
if (f[x] == x) return x;
return f[x] = find(f[x]);
}
void join(int x, int y) {
if (find(x) != find(y)) f[x] = y;
return;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
f[i] = i;
rank[i] = 1;
}
for (int i = 1; i <= m; i++) {
int opt, x, y;
cin >> opt >> x >> y;
if (opt == 1) {
join(x, y);
}
else {
int fx = find(x);
int fy = find(y);
if (fx == fy)
cout << "Y" << endl;
else
cout << "N" << endl;
}
}
return 0;
}