N, M = gets.split.map &:to_i
$parent = Array.new(N){|i|i}

def root i
  if $parent[i] == i
    i
  else
    $parent[i] = root $parent[i]
  end
end

M.times{
  x, y = gets.split.map &:to_i
  x_root = root x
  y_root = root y
  $parent[x_root] = y_root unless x_root == y_root
}
gets.to_i.times{
  x, y = gets.split.map &:to_i
  puts root(x) == root(y) ? :yes : :no
}