using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 5e3 + 5;
const int maxm = 5e5 + 5;
In ll read()
{
ll ans = 0;
char ch = getchar(), las = ' ';
while(!isdigit(ch)) las = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(las == '-') ans = -ans;
return ans;
}
In void write(ll x)
{
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
In void MYFILE()
{
#ifndef mrclr
freopen("ha.in", "r", stdin);
freopen("ha.out", "w", stdout);
#endif
}
define pr pair<int, int>
define mp make_pair
int n, m, tim[maxn][maxn];
pr q[maxm];
int l[maxm << 2], r[maxm << 2], pos[maxm];
bool vis[maxm << 2];
vector v[maxm << 2];
In void build(int L, int R, int now)
{
l[now] = L, r[now] = R;
if(L == R) {pos[L] = now; return;}
int mid = (L + R) >> 1;
build(L, mid, now << 1), build(mid + 1, R, now << 1 | 1);
}
In void update_E(int L, int R, int now, pr E)
{
if(l[now] == L && r[now] == R) {v[now].push_back(E); return;}
int mid = (l[now] + r[now]) >> 1;
if(R <= mid) update_E(L, R, now << 1, E);
else if(L > mid) update_E(L, R, now << 1 | 1, E);
else update_E(L, mid, now << 1, E), update_E(mid + 1, R, now << 1 | 1, E);
}
int p[maxn], siz[maxn], top = 0;
pr st[maxm << 2];
In int Find(int x) {return x == p[x] ? x : Find(p[x]);}
In int merge(int x, int y)
{
int px = Find(x), py = Find(y);
if(px == py) return 0;
if(siz[px] > siz[py]) swap(px, py);
p[px] = py, siz[py] += siz[px];
st[++top] = mp(px, py);
return 1;
}
In void cancel()
{
int x = st[top].first, y = st[top].second; --top;
p[x] = x, siz[y] -= siz[x];
}
int ans[maxm];
In void dfs(int now)
{
int cnt = 0;
for(auto i : v[now]) cnt += merge(i.first, i.second);
if(l[now] == r[now])
{
if(vis[l[now]]) ans[l[now]] = Find(q[l[now]].first) == Find(q[l[now]].second);
for(int i = 1; i <= cnt; ++i) cancel();
return;
}
dfs(now << 1), dfs(now << 1 | 1);
for(int i = 1; i <= cnt; ++i) cancel();
}
int main()
{
// MYFILE();
n = read(), m = read();
build(1, m, 1);
int FLG = 0;
for(int i = 1; i <= m; ++i)
{
int op = read(), x = read(), y = read();
if(x > y) swap(x, y);
if(!op) tim[x][y] = i;
else if(op == 1) update_E(tim[x][y], i, 1, mp(x, y)), tim[x][y] = 0;
else q[i] = mp(x, y), FLG = vis[i] = 1;
}
if(!FLG) return 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j) if(tim[i][j]) update_E(tim[i][j], m, 1, mp(i, j));
for(int i = 1; i <= n; ++i) p[i] = i, siz[i] = 1;
dfs(1);
for(int i = 1; i <= m; ++i) if(vis[i]) puts(ans[i] ? "Y" : "N");
return 0;
}