# definition
n, m = gets.split.map { |i| i.to_i }
@list = Array.new(n).map { [] }
m.times do
  s, t = gets.split.map { |i| i.to_i }
  @list[s] << t
  @list[t] << s
end

def init
  @result = false
  @d = []
end

def d_search(i, j)
  @d[i] = true
  @result = true if i == j
  return if @result
  @list[i].each do |k|
    d_search(k, j) unless @d[k]
  end
end

# main
q = gets.to_i
q.times do
  s, t = gets.split.map { |i| i.to_i }
  init
  d_search(s, t)
  puts @result ? "yes" : "no"
end