n, m = gets.split.map(&:to_i)
v = Array.new n
g = Array.new(n) { [] }
m.times do
  s, t = gets.split.map(&:to_i)
  g[s] << t
  g[t] << s
end
n.times do |u|
  next if v[u]
  v[u] = u
  stack = [u]
  until stack.empty?
    s = stack.pop
    v[s] = u
    g[s].each do |t|
      stack.push t unless v[t]
    end
  end
end
gets.to_i.times do
  s, t = gets.split.map(&:to_i)
  puts v[s] == v[t] ? 'yes' : 'no'
end