import sys

 

def make_connected_group(G):

    C = [None]*len(G)

    group = 0

    for i,p in enumerate(C):

        if p != None: continue

        friends = [i]

        while len(friends) > 0:

            f = friends.pop()

            if C[f] == None:

                C[f] = group

                friends += G[f]

        group += 1

    return C

 

 

if __name__=='__main__':

    n,m = list(map(int,sys.stdin.readline().split()))

    G = [[] for _ in range(n)]

    for _ in range(m):

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

        G[s].append(t)

        G[t].append(s)

    C = make_connected_group(G)

    q = int(eval(input()))

    for j,line in enumerate(sys.stdin):

        if not j < q: break

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

        print(('yes' if C[s] == C[t] else 'no'))
import sys

 

def make_connected_group(G):

    C = [None]*len(G)

    group = 0

    for i,p in enumerate(C):

        if p != None: continue

        friends = [i]

        while len(friends) > 0:

            f = friends.pop()

            if C[f] == None:

                C[f] = group

                friends += G[f]

        group += 1

    return C

 

 

if __name__=='__main__':

    n,m = list(map(int,sys.stdin.readline().split()))

    G = [[] for _ in range(n)]

    for j,line in enumerate(sys.stdin):

        if not j < m:

            q = int(line)

            break

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

        G[s].append(t)

        G[t].append(s)

    C = make_connected_group(G)

    for j,line in enumerate(sys.stdin):

        if not j < q: break

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

        print(('yes' if C[s] == C[t] else 'no'))
import sys


def make_connected_group(G):
    C = [None] * len(G)
    group = 0
    for i, p in enumerate(C):
        if p != None:
            continue
        friends = [i]
        while len(friends) > 0:
            f = friends.pop()
            if C[f] == None:
                C[f] = group
                friends += G[f]
        group += 1
    return C


if __name__ == "__main__":
    n, m = list(map(int, sys.stdin.readline().split()))
    G = [[] for _ in range(n)]
    for _ in range(m):
        s, t = list(map(int, input().split()))
        G[s].append(t)
        G[t].append(s)
    C = make_connected_group(G)
    q = int(eval(input()))
    for j, line in enumerate(sys.stdin):
        if not j < q:
            break
        s, t = list(map(int, line.split()))
        print(("yes" if C[s] == C[t] else "no"))

import sys


def make_connected_group(G):
    C = [None] * len(G)
    group = 0
    for i, p in enumerate(C):
        if p != None:
            continue
        friends = [i]
        while len(friends) > 0:
            f = friends.pop()
            if C[f] == None:
                C[f] = group
                friends += G[f]
        group += 1
    return C


if __name__ == "__main__":
    n, m = list(map(int, sys.stdin.readline().split()))
    G = [[] for _ in range(n)]
    for j, line in enumerate(sys.stdin):
        if not j < m:
            q = int(line)
            break
        s, t = list(map(int, line.split()))
        G[s].append(t)
        G[t].append(s)
    C = make_connected_group(G)
    for j, line in enumerate(sys.stdin):
        if not j < q:
            break
        s, t = list(map(int, line.split()))
        print(("yes" if C[s] == C[t] else "no"))

-    for _ in range(m): -        s, t = list(map(int, input().split())) +    for j, line in enumerate(sys.stdin): +        if not j < m: +            q = int(line) +            break +        s, t = list(map(int, line.split())) -    q = int(eval(input()))