def bfs(i, c):

    global V, C



    q = []

    j = i

    while True:

        if C[j] == -1:

            C[j] = c

            q += V[j]

        if len(q) == 0:

            break

        j = q.pop()



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

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

C = [-1] * n

for _ in range(m):

    l, r = list(map(int, input().split()))

    V[l].append(r)

    V[r].append(l)



c = 0

for i in range(n):

    if C[i] == -1:

        bfs(i, c)

        c += 1



q = int(input())

for _ in range(q):

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

    if C[s] == C[t]:

        print("yes")

    else:

        print("no")
def bfs(i, c):

    global V, C



    q = [i]

    while len(q) > 0:

        j = q.pop()

        if C[j] == -1:

            C[j] = c

            q += V[j]



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

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

C = [-1] * n

for _ in range(m):

    l, r = list(map(int, input().split()))

    V[l].append(r)

    V[r].append(l)



c = 0

for i in range(n):

    if C[i] == -1:

        bfs(i, c)

        c += 1



q = int(input())

for _ in range(q):

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

    if C[s] == C[t]:

        print("yes")

    else:

        print("no")
def bfs(i, c):
    global V, C
    q = []
    j = i
    while True:
        if C[j] == -1:
            C[j] = c
            q += V[j]
        if len(q) == 0:
            break
        j = q.pop()


n, m = list(map(int, input().split()))
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = list(map(int, input().split()))
    V[l].append(r)
    V[r].append(l)
c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1
q = int(input())
for _ in range(q):
    s, t = list(map(int, input().split()))
    if C[s] == C[t]:
        print("yes")
    else:
        print("no")

def bfs(i, c):
    global V, C
    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]


n, m = list(map(int, input().split()))
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = list(map(int, input().split()))
    V[l].append(r)
    V[r].append(l)
c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1
q = int(input())
for _ in range(q):
    s, t = list(map(int, input().split()))
    if C[s] == C[t]:
        print("yes")
    else:
        print("no")

-    q = [] -    j = i -    while True: +    q = [i] +    while len(q) > 0: +        j = q.pop() -        if len(q) == 0: -            break -        j = q.pop()