import java.io.*;
import java.math.BigInteger;
import java.util.*;
/**
* Created by Surya Vamsi on 21-Jul-15.
*/
class A {
static Map
<Integer,Set
<Integer
>>nodes
; static boolean[] vis;
static int end;
public static void main
(String[] args
) { InputReader in
= new InputReader
(System.
in); solve(in, out);
out.close();
}
int n = in.nextInt();
nodes = new HashMap<>();
while (true) {
String[] temp
= in.
readLine().
split(" "); //System.out.println(Arrays.toString(temp));
if (temp[0].equals("-1")) return;
//System.out.println(temp[0]);
if (temp[0].equals("C")) {
addConnection(x,y);
} else if (temp[0].equals("Q")) {
if(isIn(a,b))out.println("Yes");
else out.println("No");
}
}
}
static void addConnection(int a,int b){
Set<Integer>setA=nodes.get(a);Set<Integer>setB=nodes.get(b);
if(setA==null && setB==null){
Set<Integer>set=new HashSet<>();set.add(a);set.add(b);
nodes.put(a,set);nodes.put(b,set);
}
else if(setA==null){
setB.add(a);
nodes.put(a,setB);
}
else if(setB==null){
setA.add(b);nodes.put(b,setA);
}
else if(setA!=setB){
setA.addAll(setB);
if(nodes.get(x)==setB){
nodes.put(x,setA);
}
}
}
}
static boolean isIn(int a,int b){
return nodes.get(a).contains(b);
}
/*static void print() {
for (int i = 1; i < list.length; i++) {
System.out.println(i + " " + list[i]);
}
}*/
static class InputReader {
private boolean finished = false;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1)
return -1;
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
return -1;
}
if (numChars <= 0)
return -1;
}
return buf[curChar];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
while (s.trim().length() == 0)
s = readLine0();
return s;
}
public String readLine
(boolean ignoreEmptyLines
) { if (ignoreEmptyLines)
return readLine();
else
return readLine0();
}
try {
throw new InputMismatchException();
}
}
public char readCharacter() {
int c = read();
while (isSpaceChar(c))
c = read();
return (char) c;
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res
* Math.
pow(10, nextInt
()); if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res
* Math.
pow(10, nextInt
()); if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1)
read();
return value == -1;
}
return readString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}