def nxt(arr)
	arr.each do |val|
		unless $grp[val]
			return val
		end
	end
	return nil
end

def dfs_src(s,id)
	stk = [s]
	$grp[s] = id
	while stk != []
		u = nxt($l[stk.last])
		if u
			stk.push(u)
			$grp[u] = id
		else
			stk.pop
		end
	end
end
$grp = []

result = []
$l=[]
n, m = gets.chomp.split(" ").map(&:to_i)
m.times do
	s,t = gets.chomp.split(" ").map(&:to_i)
	if $l[s]
		$l[s].push(t)
	else
		$l[s] = [t]
	end
	if $l[t]
		$l[t].push(s)
	else
		$l[t] = [s]
	end
end
q = gets.chomp.to_i

list = []
i = 0
while i <= n
	unless $grp[i]
		if $l[i]
			dfs_src(i, i)
		end
	end
	i += 1
end

q.times do
	res = "no"
	s, t = gets.chomp.split.map(&:to_i)
	if $grp[s] == $grp[t] && $grp[s] != nil
		result.push("yes")
	else
		result.push("no")
	end
end

result.each do |r|
	puts r
end
