class Node
  attr_reader :id, :siblings
  attr_accessor :gid

  def initialize(id)
    @id = id
    @siblings = []
    @gid = nil
  end

  def <<(sibling)
    @siblings << sibling
  end
end

if $PROGRAM_NAME == __FILE__
  n, m = gets.chomp.split.map(&:to_i)

  nodes = Array.new(n)

  m.times do
    id1, id2 = gets.chomp.split.map(&:to_i)
    nodes[id1] ||= Node.new(id1)
    nodes[id2] ||= Node.new(id2)
    nodes[id1] << nodes[id2]
    nodes[id2] << nodes[id1]
  end

  gid = 0

  nodes.each do |node|
    next unless node
    next if node.gid

    gid += 1

    node.gid = gid

    queue = [node]

    until queue.empty?
      current = queue.shift

      current.siblings.each do |sibling|
        next if sibling.gid
        sibling.gid = gid
        queue << sibling
      end
    end
  end

  q = gets.to_i

  q.times do
    id1, id2 = gets.chomp.split.map(&:to_i)
    node1 = nodes[id1]
    node2 = nodes[id2]

    puts node1 && node2 && node1.gid == node2.gid ? 'yes' : 'no'
  end
end