require('set')

def freind_search(matrix)
	visited = Set[]
	search = lambda do |a, b|
		return false if visited.include?(a)
		return true if a == b
		visited << a

		matrix[a].each_index
			select { |i| matrix[a][i] && !visited.include?(i) }.
			detect { |i| search.call(i, b) }
	end
end

n, m = STDIN.gets.split.map!(&:to_i)
matrix = Array.new(n) { Array.new(n, false) }

m.times do
	vertex, freind = STDIN.gets.split.map!(&:to_i)
	matrix[vertex][freind] = matrix[freind][vertex] = true
end

questions = STDIN.gets.to_i
questions.times do
	a, b = STDIN.gets.split.map!(&:to_i)
	puts freind_search(matrix).call(a, b) ? "yes" : "no"
end