require('set')

def freind_search(matrix)
	visited = Set[]
	search = lambda do |base, target|
		return true if base == target

		queue = [].push(base)
		until queue.empty?
			v = queue.shift
			visited.add(v)

			found = matrix[v].each_index.
				select { |i| matrix[v][i] && !visited.include?(i) }.
				each { |i| queue.push(i) }.
				find { |i| i == target }

			if found
				matrix[v][found] = true
				return true
			end
		end

	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