n, m = list(map(int, input().split()))

rootList = [-1 for i in range(n)]

 

def getRoot(x):

    if rootList[x] < 0:

        rootList[x] = x

    elif rootList[x] != x:

        rootList[x] = getRoot(rootList[x])

    return rootList[x]

 

 

def setSameRoot(x, y):

    x = getRoot(x)

    y = getRoot(y)

    rootList[x], rootList[y] = min(x, y), min(x, y)

 

for i in range(m):

    s, t = list(map(int, input().split()))

    setSameRoot(s, t)

q = int(eval(input()))

for i in range(q):

    s, t = list(map(int, input().split()))

    print(("yes" if getRoot(s) == getRoot(t) != -1 else "no"))
n, m = list(map(int, input().split()))

rootList = [-1 for i in range(n)]

 

def getRoot(x):

    r = rootList[x]

    if r < 0:

        rootList[x] = x

    elif r != x:

        rootList[x] = getRoot(r)

    return rootList[x]

 

 

def setSameRoot(x, y):

    x = getRoot(x)

    y = getRoot(y)

    if x != y:

        rootList[x] = rootList[y] = min(x, y)

 

for i in range(m):

    s, t = list(map(int, input().split()))

    setSameRoot(s, t)

q = int(eval(input()))

for i in range(q):

    s, t = list(map(int, input().split()))

    print(("yes" if getRoot(s) == getRoot(t) else "no"))
n, m = list(map(int, input().split()))
rootList = [-1 for i in range(n)]


def getRoot(x):
    if rootList[x] < 0:
        rootList[x] = x
    elif rootList[x] != x:
        rootList[x] = getRoot(rootList[x])
    return rootList[x]


def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    rootList[x], rootList[y] = min(x, y), min(x, y)


for i in range(m):
    s, t = list(map(int, input().split()))
    setSameRoot(s, t)
q = int(eval(input()))
for i in range(q):
    s, t = list(map(int, input().split()))
    print(("yes" if getRoot(s) == getRoot(t) != -1 else "no"))

n, m = list(map(int, input().split()))
rootList = [-1 for i in range(n)]


def getRoot(x):
    r = rootList[x]
    if r < 0:
        rootList[x] = x
    elif r != x:
        rootList[x] = getRoot(r)
    return rootList[x]


def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x] = rootList[y] = min(x, y)


for i in range(m):
    s, t = list(map(int, input().split()))
    setSameRoot(s, t)
q = int(eval(input()))
for i in range(q):
    s, t = list(map(int, input().split()))
    print(("yes" if getRoot(s) == getRoot(t) else "no"))

-    if rootList[x] < 0: +    r = rootList[x] +    if r < 0: -    elif rootList[x] != x: -        rootList[x] = getRoot(rootList[x]) +    elif r != x: +        rootList[x] = getRoot(r) -    rootList[x], rootList[y] = min(x, y), min(x, y) +    if x != y: +        rootList[x] = rootList[y] = min(x, y) -    print(("yes" if getRoot(s) == getRoot(t) != -1 else "no")) +    print(("yes" if getRoot(s) == getRoot(t) else "no"))