# unionfindぽいけどもっと単純に答えるらしい
n, m = gets.chomp.split.map(&:to_i)
arr = Array.new(n).map{[]}
m.times do
  a, b = gets.chomp.split.map(&:to_i)
  arr[a] << b
  arr[b] << a
end
q = gets.chomp.to_i
q.times do
  a, b = gets.chomp.split.map(&:to_i)
  # puts "a: #{a} b: #{b}"
  stack = arr[a].clone
  used = [a]
  find = false
  # puts "#stack init: #{stack}"
  until stack.empty?
    nex = stack.pop
    # puts "次に探すやつ #{nex}"
    if nex == b
      find = true
      break
    end
    # p stack
    # puts "next #{nex}"
    arr[nex].each do |i|
      next if used.include?(i)
      used << i
      stack << i
    end
  end
  if find
    puts "yes"
  else
    puts "no"
  end
end
