class SNS
  def initialize(n)
    @group_tbl = []
    @priority = []
    n.times{|i|
      @group_tbl[i] = i
      @priority[i] = 0
    }
  end

  def setGroup(i, j)
    ii = theGroup(i)
    jj = theGroup(j)
    if @priority[ii] > @priority[jj] then
      @group_tbl[jj] = ii
    else
      @group_tbl[ii] = jj
      @priority[jj] += 1 if @priority[ii] == @priority[jj]
    end
  end

  def isSameGroup(i, j)
    return theGroup(i) == theGroup(j)
  end

  def theGroup(i)
    @group_tbl[i] = theGroup(@group_tbl[i]) if i != @group_tbl[i]
    return @group_tbl[i]
  end
end
n, m = gets.split.map(&:to_i)

sns = SNS.new(n)

m.times{
  i, j = gets.split.map(&:to_i)
  sns.setGroup(i, j)
}
q = gets.to_i
q.times{
  s, t = gets.split.map(&:to_i)
  if sns.isSameGroup(s, t)
    puts "yes"
  else
    puts "no"
  end
}