Vertex = Struct.new(:id, :adjacencies, :group)

def grouping!(vertex, group)
	return unless vertex.group.nil?
	vertex.group = group
	vertex.adjacencies.each { |v| grouping!(v, group) }
end

n, m = STDIN.gets.split.map(&:to_i)
vertex_list = Array.new(n) { |i| Vertex.new(i, []) }
m.times do
	vertex_id, friend_id = STDIN.gets.split.map(&:to_i)
	vertex_list[vertex_id].adjacencies << vertex_list[friend_id]
end

vertex_list.each_with_index { |v, i| grouping!(v, i) }

questions = STDIN.gets.to_i
questions.times do
	a, b = STDIN.gets.split.map(&:to_i)
	puts vertex_list[a].group == vertex_list[b].group ? "yes" : "no"
end