# -*- coding: utf-8 -*-



def assignColor(G):

    n = len(G)

    C = [-1 for i in range(n)]

    for i in range(n):

        if C[i] == -1:

            C = BFS(G, i, C)

    return C



#@profile

def BFS(G, start, C):

    n = len(G)

    Q = []



    Q.append(start)

    C[start] = start



    while len(Q) != 0:

        u = Q.pop(0)

        v = [i for i in G[u] if C[i] == -1] # v := ??£??\???????????????????????¢?´¢??????????????????

        

        for i in v:

            Q.append(i)

            C[i] = C[start]

    

    return C



def main():

    

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

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



    for i in range(m):

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

        G[s].append(t)

        G[t].append(s)



    C = assignColor(G)

        

    q = int(eval(input()))

    

    for i in range(q):

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

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

            print("yes")

        else:

            print("no")

            

if __name__ == "__main__":

    main()    
#!/usr/bin/env python

# -*- coding: utf-8 -*-

 

import sys

 

 

def assign_color():

    _color = 1

    for m in range(vertices_num):

        if vertices_status_list[m] == -1:

            graph_dfs(m, _color)

            _color += 1

    return None

 

 

def graph_dfs(vertex, color):

    vertices_stack = list()

    vertices_stack.append(vertex)

    vertices_status_list[vertex] = color

 

    while vertices_stack:

        current_vertex = vertices_stack[-1]

        vertices_stack.pop()

        for v in adj_list[current_vertex]:

            if vertices_status_list[v] == -1:

                vertices_status_list[v] = color

                vertices_stack.append(v)

    return None

 

 

def solve():

    for relation in relation_info:

        key, value = list(map(int, relation.split()))

        adj_list[key].append(value)

        adj_list[value].append(key)

 

    assign_color()

 

    # print(adj_list)

    for question in question_list:

        start, target = list(map(int, question.split()))

        if vertices_status_list[start] == vertices_status_list[target]:

            print("yes")

        else:

            print("no")

    return vertices_status_list

 

 

if __name__ == '__main__':

    _input = sys.stdin.readlines()

    vertices_num, relation_num = list(map(int, _input[0].split()))

 

    relation_info = _input[1:relation_num + 1]

 

    question_num = int(_input[relation_num + 1])

    question_list = _input[relation_num + 2:]

 

    adj_list = tuple([[] for _ in range(vertices_num)])

    vertices_status_list = [-1] * vertices_num

    ans = solve()
# -*- coding: utf-8 -*-
def assignColor(G):
    n = len(G)
    C = [-1 for i in range(n)]
    for i in range(n):
        if C[i] == -1:
            C = BFS(G, i, C)
    return C


# @profile
def BFS(G, start, C):
    n = len(G)
    Q = []
    Q.append(start)
    C[start] = start
    while len(Q) != 0:
        u = Q.pop(0)
        v = [
            i for i in G[u] if C[i] == -1
        ]  # v := ??£??\???????????????????????¢?´¢??????????????????
        for i in v:
            Q.append(i)
            C[i] = C[start]
    return C


def main():
    n, m = list(map(int, input().split()))
    G = [[] for i in range(n)]
    for i in range(m):
        s, t = list(map(int, input().split()))
        G[s].append(t)
        G[t].append(s)
    C = assignColor(G)
    q = int(eval(input()))
    for i in range(q):
        s, t = list(map(int, input().split()))
        if C[s] == C[t]:
            print("yes")
        else:
            print("no")


if __name__ == "__main__":
    main()

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys


def assign_color():
    _color = 1
    for m in range(vertices_num):
        if vertices_status_list[m] == -1:
            graph_dfs(m, _color)
            _color += 1
    return None


def graph_dfs(vertex, color):
    vertices_stack = list()
    vertices_stack.append(vertex)
    vertices_status_list[vertex] = color
    while vertices_stack:
        current_vertex = vertices_stack[-1]
        vertices_stack.pop()
        for v in adj_list[current_vertex]:
            if vertices_status_list[v] == -1:
                vertices_status_list[v] = color
                vertices_stack.append(v)
    return None


def solve():
    for relation in relation_info:
        key, value = list(map(int, relation.split()))
        adj_list[key].append(value)
        adj_list[value].append(key)
    assign_color()
    # print(adj_list)
    for question in question_list:
        start, target = list(map(int, question.split()))
        if vertices_status_list[start] == vertices_status_list[target]:
            print("yes")
        else:
            print("no")
    return vertices_status_list


if __name__ == "__main__":
    _input = sys.stdin.readlines()
    vertices_num, relation_num = list(map(int, _input[0].split()))
    relation_info = _input[1 : relation_num + 1]
    question_num = int(_input[relation_num + 1])
    question_list = _input[relation_num + 2 :]
    adj_list = tuple([[] for _ in range(vertices_num)])
    vertices_status_list = [-1] * vertices_num
    ans = solve()

+#!/usr/bin/env python -def assignColor(G): -    n = len(G) -    C = [-1 for i in range(n)] -    for i in range(n): -        if C[i] == -1: -            C = BFS(G, i, C) -    return C +import sys -# @profile -def BFS(G, start, C): -    n = len(G) -    Q = [] -    Q.append(start) -    C[start] = start -    while len(Q) != 0: -        u = Q.pop(0) -        v = [ -            i for i in G[u] if C[i] == -1 -        ]  # v := ??£??\???????????????????????¢?´¢?????????????????? -        for i in v: -            Q.append(i) -            C[i] = C[start] -    return C +def assign_color(): +    _color = 1 +    for m in range(vertices_num): +        if vertices_status_list[m] == -1: +            graph_dfs(m, _color) +            _color += 1 +    return None -def main(): -    n, m = list(map(int, input().split())) -    G = [[] for i in range(n)] -    for i in range(m): -        s, t = list(map(int, input().split())) -        G[s].append(t) -        G[t].append(s) -    C = assignColor(G) -    q = int(eval(input())) -    for i in range(q): -        s, t = list(map(int, input().split())) -        if C[s] == C[t]: +def graph_dfs(vertex, color): +    vertices_stack = list() +    vertices_stack.append(vertex) +    vertices_status_list[vertex] = color +    while vertices_stack: +        current_vertex = vertices_stack[-1] +        vertices_stack.pop() +        for v in adj_list[current_vertex]: +            if vertices_status_list[v] == -1: +                vertices_status_list[v] = color +                vertices_stack.append(v) +    return None + + +def solve(): +    for relation in relation_info: +        key, value = list(map(int, relation.split())) +        adj_list[key].append(value) +        adj_list[value].append(key) +    assign_color() +    # print(adj_list) +    for question in question_list: +        start, target = list(map(int, question.split())) +        if vertices_status_list[start] == vertices_status_list[target]: +    return vertices_status_list -    main() +    _input = sys.stdin.readlines() +    vertices_num, relation_num = list(map(int, _input[0].split())) +    relation_info = _input[1 : relation_num + 1] +    question_num = int(_input[relation_num + 1]) +    question_list = _input[relation_num + 2 :] +    adj_list = tuple([[] for _ in range(vertices_num)]) +    vertices_status_list = [-1] * vertices_num +    ans = solve()