class User
  attr_reader :id
  def initialize(id)
    @id = id
    @root = true
    @parent = self
  end

  def connect(other)
    if @parent == self
      @parent = other.union
    else
      @parent.union.connect(other.union)
    end
  end

  def union
    @parent = @parent.union if @parent != self
    return @parent
  end

  def ==(other)
    @id == other.id
  end

  def inspect
    @id
  end
  
end
def main
  n, m = gets.split(" ").map(&:to_i)
  user = Array.new(n){|i|User.new(i)}
  m.times do
    arg = gets.split(" ").map(&:to_i)
    user[arg[0]].connect(user[arg[1]])
  end
  gets.to_i.times do
    arg = gets.split(" ").map(&:to_i)
    if user[arg[0]].union == user[arg[1]].union
      puts "yes"
    else
      puts "no"
    end
  end
end
main