Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"container/list"
	"bytes"
)

const MaxNode int = 1e5

var graph [][] int
var color []int
var N int

func bfs(u, c int) {
	l := list.New()
	l.PushBack(u)
	for ;l.Len()!=0; {
		u = l.Front().Value.(int)
		color[u] = c
		l.Remove(l.Front())
		for i:=0; i<len(graph[u]); i++ {
			if color[graph[u][i]] == 0 {
				l.PushBack(graph[u][i])
			}
		}
	}
}

func assignColor() {
	id := 1
	for u:=0; u<N; u++ {
		if color[u] == 0 {
			bfs(u, id)
			id ++
		}
	}
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}


func buildGraph(scanner *bufio.Scanner) {
	N = nextInt(scanner)
	color = make([]int, N)
	graph = make([][]int, N)
	m := nextInt(scanner)
	for i:=0; i<m; i++ {
		n1 := nextInt(scanner)
		n2 := nextInt(scanner)
		graph[n1] = append(graph[n1], n2)
		graph[n2] = append(graph[n2], n1)
	}
}

func answer(scanner *bufio.Scanner) {
	var outBuffer bytes.Buffer
	cnt := nextInt(scanner)
	for i:=0; i<cnt; i++ {
		n1 := nextInt(scanner)
		n2 := nextInt(scanner)
		if color[n1] == color[n2] {
			outBuffer.WriteString("yes\n")
		} else {
			outBuffer.WriteString("no\n")
		}
	}
	fmt.Printf("%s", outBuffer.String())
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	buildGraph(scanner)
	assignColor()
	answer(scanner)
}

Python: 
def BFS(s = 0, group_num = 0):
    Q.pop(0)
    color[s] = 2
    for j in range(len(A[s])):
        if color[A[s][j]] == 0:
            Q.append(A[s][j])
            color[A[s][j]] = 1
            affil[A[s][j]] = group_num
    if len(Q) != 0:
        BFS(Q[0], group_num)

entry = map(int, raw_input().split())
n = entry[0]
m = entry[1]

A = range(n)
for i in A:
    A[i] = list()
for i in range(m):
    entry = map(int, raw_input().split())
    s = entry[0]
    t = entry[1]
    A[s].append(t)
    A[t].append(s)

color = [0] * n
affil = [0] * n
group_num = -1
for i in range(n):
    if color[i] == 0:
        Q = [i]
        group_num = group_num + 1
        affil[i] = group_num
        BFS(i, group_num)

q = int(raw_input())
for i in range(q):
    entry = map(int, raw_input().split())
    if affil[entry[0]] == affil[entry[1]]:
        print("yes")
    else:
        print("no")

Python: def dfs(s):
    global t
    if s == t:
        return True
    DP[s]=1
    for i in F[s]:
        if not DP[i]:
            if dfs(i):
                return True
    return False
    
n,m = [int(i) for i in input().split()]
F = [{}]*n
for _ in range(m):
    i,j = [int(i) for i in input().split()]
    F[i][j] = 1
    F[j][i] = 1
q = int(input())
for i in range(q):
    DP = [0]*n
    s,t = [int(i) for i in input().split()]
    if dfs(s):
        print("yes")
    else:
        print("no")

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

Python: n, m = map(int, input().split())
relations = [[] for _ in range(n)]

for i in range(m):
    s, t = map(int, input().split())
    relations[s] += [t]
    relations[t] += [s]
friend_id = [None] * n
for s, t in enumerate(relations):
    if t:
        queue = [s]
        while len(queue):
            k = queue.pop()
            friend_id[k] = s
            queue += relations[k]
            relations[k] = []

q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print('yes' if friend_id[s] != None and friend_id[s] == friend_id[t] else'no')

Python: def connect(o,s,t):
    global ct
    if color[s]!="white" or ct!=0:
        return
    if fr[o][t]==t:
        ct+=1
    color[s]="grey"
    for i in fr[s]:
        if i==-1:
            continue
        elif i==t or ct!=0:
             ct+=1
             break
        else:
            fr[o][i]=i
            fr[i][o]=o
            connect(o,i,t)
            
n,m=map(int,raw_input().split())
fr=[[-1]*n for i in xrange(n)]
for i in xrange(m):
    s,t=map(int,raw_input().split())
    fr[s][t]=t
    fr[t][s]=s
q=input()
for i in xrange(q):
    ct=0
    color=["white"]*n
    s,t=map(int,raw_input().split())
    connect(s,s,t)
    if ct==0:
        print('no')
    else:
        print('yes')
        fr[s][t]=t
        fr[t][s]=s

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

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

for i in range(m):
    com = list(map(int, input().split()))
    a[com[0]].append(com[1])

q = int(input())

from collections import deque
queue = deque()


for j in range(q):
    memo = [0 for i in range(n)]
    data = list(map(int,input().split()))
    memo[data[0]] = 1
    queue.append(data[0])

    try:
        while len(queue) != 0:
            b = queue.popleft()
            if len(a[b]) != 0:
                for k in a[b]:
                    if memo[k] == 0:
                        memo[k] = 1
                        queue.append(k)
                        if k == data[1]:
                            print("yes")
                            raise Exception
        print("no")
    except Exception:
        pass

Python: #coding:utf-8

def CC(root,dist):
    for i in range(len(dist)):
        if i==root[0]:
            dist[i]=dist[i]+[root[1]]
        elif i==root[1]:
            dist[i]=dist[i]+[root[0]]
        
def Check(dist,start,end,clist):
    ans="no"
    if len(dist[end])!=0:
        if start in dist[end]:
            ans="yes"
        else:
            clist.append(end)
            for d in dist[end]:
                if d!=end and d not in clist:
                    ans=Check(dist,start,d,clist)
    return ans
    
if __name__=="__main__":
    I=input()
    n=int(I.split(" ")[0])
    m=int(I.split(" ")[1])
    A=[]
    for i in range(m):
        A.append(list(map(int,input().split(" "))))
    dist=[[]]*n
    for i in range(m):
        CC(A[i],dist)
    q=int(input())
    for i in range(q):
        qList=list(map(int,input().split(" ")))
        print(Check(dist,qList[0],qList[1],[]))

Python: def bfs(graph, start, goal):
    visited = {start: None}
    unvisited = [start]
    while unvisited:
        now = unvisited[0]
        if now == goal:
            return "yes"
        unvisited = unvisited[1:]
        for next in graph[now][1:]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = map(int, input().split())
g = [[i] for i in range(n)]

for i in range(m):
    inp = list(map(int, input().split()))
    g[inp[0]].append(inp[1])
    g[inp[1]].append(inp[0])

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    print(bfs(g, s, t))

Python: #coding:utf-8
n, r = map(int,input().split())
Q = []
M = [[] for j in range(n)]
for i in range(r):
    i,j = map(int,input().split())
    M[i].append(j)
    M[j].append(i)


def search(person, target):
    Q = []
    Q.append(person)
    color = [0 for i in range(n)]
    while Q != []:
        u = Q.pop(0)
        if u ==  target:
            print("yes")
            break
        color[u] = 1
        data = M[u]
        for v in data:
            if color[v] == 0:
                color[v] = 1
                Q.append(v)
        color[u] = 2
    else:
        print("no")

num = int(input())
for i in range(num):
    person, target = map(int,input().split())
    search(person, target)