
class MyGraph
  attr_accessor :vec

  def initialize(n)
    @vec = Array.new(n).map{Array.new()}
  end

  def create_link(i,j)
    @vec[i].push(j)
    @vec[j].push(i)
  end

  def find_friend(i,j)
    @log = Array.new(@vec.length,false)
    return depth_search(i,j)
  end

  def depth_search(i,j)
    #p "begin:#{i},#{j}"
    #p " log:#{@log}"
    if @log[i]
      return "no"
    else
      @log[i]=true
    end

    ret = "no"
    @vec[i].each do |v|
      if v==j
        ret = "yes"
      else
        ret = depth_search(v,j)
      end
      break if ret=="yes"
    end
    return ret
    #p "end:#{i},#{j}"
  end

end

n,m = STDIN.gets().split(' ').map{ |i| i.to_i}

graph = MyGraph.new(n)

m.times do |i|
  i, j = STDIN.gets().split(' ').map{ |i| i.to_i }
  graph.create_link(i,j)
end

#p graph.vec

q = STDIN.gets().to_i
q.times do
  i,j = STDIN.gets().split(' ').map{ |i| i.to_i }
  print "#{graph.find_friend(i,j)}\n"
end