N, M = gets.split.map &:to_i
$parent = []

def trace_parent i
  stack = []
  t = i
  loop{
    if $parent[t]
      stack << t
      t = $parent[t]
    else
      break
    end
  }
  stack.each{|e|
    $parent[e] = t
  }
  t
end

M.times{
  s, t = gets.split.map &:to_i
  if $parent[s] == nil
    if $parent[t] == nil
      $parent[t] = s
    else
      root = trace_parent(t)
      $parent[s] = root
      $parent[t] = root
    end
  elsif $parent[t] == nil
    root = trace_parent(s)
    $parent[s] = root
    $parent[t] = root
  else
    s_root = trace_parent(s)
    $parent[t] = s_root
  end
}
gets.to_i.times{
  s, t = gets.split.map &:to_i
  puts trace_parent(s) == trace_parent(t) ? :yes : :no
}