def MAIN():

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

    li = [i for i in range(n)]

    def f(a):

        if li[a] == a:

            return a

        li[a] = f(li[a])

        return li[a]

    def f2(a, b):

        if li[a] == a:

            li[a] = b

            return

        f2(li[a], b)

        li[a] = b

    def solve(a, b):

        if f(a) == f(b):

            return "yes"

        return "no"

    for _ in range(m):

        x, y = list(map(int, input().split()))

        if f(x) > f(y):

            f2(x, li[y])

        else:

            f2(y, li[x])

    for _ in range(int(eval(input()))):

        x, y = list(map(int, input().split()))

        print((solve(x, y)))

MAIN()



import sys

readline = sys.stdin.readline

def MAIN():

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

    li = [i for i in range(n)]

    def f(a):

        if li[a] == a:

            return a

        li[a] = f(li[a])

        return li[a]

    def f2(a, b):

        if li[a] == a:

            li[a] = b

            return

        f2(li[a], b)

        li[a] = b

    def solve(a, b):

        if f(a) == f(b):

            return "yes"

        return "no"

    for _ in range(m):

        x, y = list(map(int, readline().split()))

        if f(x) > f(y):

            f2(x, li[y])

        else:

            f2(y, li[x])

    for _ in range(int(eval(input()))):

        x, y = list(map(int, readline().split()))

        print((solve(x, y)))

MAIN()



def MAIN():
    n, m = list(map(int, input().split()))
    li = [i for i in range(n)]

    def f(a):
        if li[a] == a:
            return a
        li[a] = f(li[a])
        return li[a]

    def f2(a, b):
        if li[a] == a:
            li[a] = b
            return
        f2(li[a], b)
        li[a] = b

    def solve(a, b):
        if f(a) == f(b):
            return "yes"
        return "no"

    for _ in range(m):
        x, y = list(map(int, input().split()))
        if f(x) > f(y):
            f2(x, li[y])
        else:
            f2(y, li[x])
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        print((solve(x, y)))


MAIN()

import sys

readline = sys.stdin.readline


def MAIN():
    n, m = list(map(int, input().split()))
    li = [i for i in range(n)]

    def f(a):
        if li[a] == a:
            return a
        li[a] = f(li[a])
        return li[a]

    def f2(a, b):
        if li[a] == a:
            li[a] = b
            return
        f2(li[a], b)
        li[a] = b

    def solve(a, b):
        if f(a) == f(b):
            return "yes"
        return "no"

    for _ in range(m):
        x, y = list(map(int, readline().split()))
        if f(x) > f(y):
            f2(x, li[y])
        else:
            f2(y, li[x])
    for _ in range(int(eval(input()))):
        x, y = list(map(int, readline().split()))
        print((solve(x, y)))


MAIN()

+import sys + +readline = sys.stdin.readline + + -        x, y = list(map(int, input().split())) +        x, y = list(map(int, readline().split())) -        x, y = list(map(int, input().split())) +        x, y = list(map(int, readline().split()))