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()

import sys

def s():

 e=sys.stdin.readline

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

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

 C=[0]*n

 k=0

 for _ in[0]*m:

  s,t=list(map(int,e().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(e()):

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

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

if'__main__'==__name__:s()

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()

import sys


def s():
    e = sys.stdin.readline
    n, m = list(map(int, e().split()))
    P = [[] for _ in [0] * n]
    C = [0] * n
    k = 0
    for _ in [0] * m:
        s, t = list(map(int, e().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(e()):
        a, b = list(map(int, e().split()))
        print((["no", "yes"][C[a] == C[b]]))


if "__main__" == __name__:
    s()

+import sys + + -    n, m = list(map(int, input().split())) +    e = sys.stdin.readline +    n, m = list(map(int, e().split())) -        s, t = list(map(int, input().split())) +        s, t = list(map(int, e().split())) -    for _ in [0] * int(eval(input())): -        a, b = list(map(int, input().split())) +    for _ in [0] * int(e()): +        a, b = list(map(int, e().split()))