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

P=[[]for _ in[0]*n]

C=[0]*n

k=0

for _ in[0]*m:

 s,t=list(map(int,input().split()));P[s]+=[t];P[t]+=[s]

for i in range(n):

 k+=1

 if C[i]<1:

  s=[i];C[i]=k

  while s:

   u=s.pop()

   for v in P[u]:

    if C[v]<1:C[v]=k;s+=[v]

for _ in[0]*int(eval(input())):

 a,b=list(map(int,input().split()))

 print((['no','yes'][C[a]==C[b]]))

def s():

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

 P=[[]for _ in[0]*n]

 C=[0]*n

 k=0

 for _ in[0]*m:

  s,t=list(map(int,input().split()));P[s]+=[t];P[t]+=[s]

 for i in range(n):

  k+=1

  if C[i]<1:

   s=[i];C[i]=k

   while s:

    u=s.pop()

    for v in P[u]:

     if C[v]<1:C[v]=k;s+=[v]

 for _ in[0]*int(eval(input())):

  a,b=list(map(int,input().split()))

  print((['no','yes'][C[a]==C[b]]))

if'__main__'==__name__:s()

n, m = list(map(int, input().split()))
P = [[] for _ in [0] * n]
C = [0] * n
k = 0
for _ in [0] * m:
    s, t = list(map(int, input().split()))
    P[s] += [t]
    P[t] += [s]
for i in range(n):
    k += 1
    if C[i] < 1:
        s = [i]
        C[i] = k
        while s:
            u = s.pop()
            for v in P[u]:
                if C[v] < 1:
                    C[v] = k
                    s += [v]
for _ in [0] * int(eval(input())):
    a, b = list(map(int, input().split()))
    print((["no", "yes"][C[a] == C[b]]))

def s():
    n, m = list(map(int, input().split()))
    P = [[] for _ in [0] * n]
    C = [0] * n
    k = 0
    for _ in [0] * m:
        s, t = list(map(int, input().split()))
        P[s] += [t]
        P[t] += [s]
    for i in range(n):
        k += 1
        if C[i] < 1:
            s = [i]
            C[i] = k
            while s:
                u = s.pop()
                for v in P[u]:
                    if C[v] < 1:
                        C[v] = k
                        s += [v]
    for _ in [0] * int(eval(input())):
        a, b = list(map(int, input().split()))
        print((["no", "yes"][C[a] == C[b]]))


if "__main__" == __name__:
    s()

-n, m = list(map(int, input().split())) -P = [[] for _ in [0] * n] -C = [0] * n -k = 0 -for _ in [0] * m: -    s, t = list(map(int, input().split())) -    P[s] += [t] -    P[t] += [s] -for i in range(n): -    k += 1 -    if C[i] < 1: -        s = [i] -        C[i] = k -        while s: -            u = s.pop() -            for v in P[u]: -                if C[v] < 1: -                    C[v] = k -                    s += [v] -for _ in [0] * int(eval(input())): -    a, b = list(map(int, input().split())) -    print((["no", "yes"][C[a] == C[b]])) +def s(): +    n, m = list(map(int, input().split())) +    P = [[] for _ in [0] * n] +    C = [0] * n +    k = 0 +    for _ in [0] * m: +        s, t = list(map(int, input().split())) +        P[s] += [t] +        P[t] += [s] +    for i in range(n): +        k += 1 +        if C[i] < 1: +            s = [i] +            C[i] = k +            while s: +                u = s.pop() +                for v in P[u]: +                    if C[v] < 1: +                        C[v] = k +                        s += [v] +    for _ in [0] * int(eval(input())): +        a, b = list(map(int, input().split())) +        print((["no", "yes"][C[a] == C[b]])) + + +if "__main__" == __name__: +    s()