#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <fstream>
#include <iostream>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 12345
#define MAX 1037471823
using namespace std;
int l[MS], r[MS], h[MS], ph[MS];
int n, m, x, y;
bool rev[MS];
char q[10];
void Down(int x) { int k; k = l[x], l[x] = r[x], r[x] = k, rev[x]^=1, rev[l[x]]^=1, rev[r[x]]^=1; }
void Splay(int x)
{
if (!x) return; int o = h[x]; if (rev[x]) Down(x);
while (o)
{
if (rev[o]) { Down(o); Down(x); } if (!h[o]) ph[x] = ph[o], ph[o] = 0;
if (l[o] == x) { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o]; l[o] = r[x]; h[r[x]] = o; h[o] = x, r[x] = o; }
else { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o]; r[o] = l[x]; h[l[x]] = o; h[o] = x, l[x] = o; }
o = h[x];
}
}
void Acc(int x)
{
int o; Splay(x); ph[r[x]] = x, h[r[x]] = 0, r[x] = 0;
while (ph[x]) { o = ph[x]; Splay(o); ph[r[o]] = o, h[r[o]] = 0, r[o] = x, h[x] = o, ph[x] = 0, x = o; }
}
void Evert(int x) { Acc(x); Splay(x); rev[x]^=1; }
int FindR(int x) { Acc(x); Splay(x); int o = x; while (l[o]) o = l[o]; return o; }
void Link(int x, int y) { Evert(x); Evert(y); Splay(y); ph[y] = x; }
void Cut(int x, int y) { Evert(x); Acc(y); Splay(y); h[x] = l[y] = 0; }
int main()
{
scanf("%d%d", &n, &m);
rep(i, 1, m)
{
scanf("%s%d%d", q, &x, &y);
if (q[0] == 'D') Cut(x, y);
else if (q[0] == 'C') Link(x, y);
else { if (FindR(x) == FindR(y)) printf("Yes\n"); else printf("No\n"); }
}
return 0;
}
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGNzd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