#include <iostream>
using namespace std;
const int N = 100010;
int p[N], m, n, a, b;
int find(int x) {
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i ++) p[i] = i;
while (m --) {
char op[2];
cin >> op >> a >> b;
if (op[0] == 'M') p[find(a)] = find(b);
else cout<< (find(a) == find(b)? "Yes":"No") << endl;
}
return 0;
}