UNDEF = -1



def dfs(r, c)
	s = [r]
	$color[r] = c
	
	while not s.empty?
		u = s.pop
		$g[u].size.times do |i|
			v = $g[u][i]
			if $color[v] == UNDEF
				$color[v] = c
				s.push(v)
			end
		end
	end
end



def assignColor()
	id = 1
	$color = Array.new($n, UNDEF)
	$n.times do |u|
		if $color[u] == UNDEF
			dfs(u, id)
			id += 1
		end
	end
end



$n, m = gets.split.map &:to_i
$g = Array.new($n){ Array.new(0) }

m.times do
	s, t = gets.split.map &:to_i
	$g[s].push(t)
	$g[t].push(s)
end

assignColor()

q = gets.to_i

q.times do
	s, t = gets.split.map &:to_i
	if $color[s] == $color[t]
		puts "yes"
	else
		puts "no"
	end
end