def breadth_first_search(s, rel_tbl, checked)
  ans = [s]
  checked[s] = 1
  q = [s]
  loop do
    break if q.size == 0
    next_q = []
    q.each{|i|
      rel_tbl[i].each{|j|
        if checked[j] < 0 then
          ans.each{|k|
            rel_tbl[k] << j
          }
          checked[j] = 1
          next_q << j
          ans << j
        end
      }
    }
    q = next_q
  end
  return ans
end

n, m = gets.split.map(&:to_i)

rel_tbl = Array.new(n){[]}
checked = Array.new(n){-1}

m.times{
  i, j = gets.split.map(&:to_i)
  rel_tbl[i] << j
  rel_tbl[j] << i
}


q = gets.to_i
q.times{
  s, t = gets.split.map(&:to_i)
  checked = Array.new(n){-1}
  if breadth_first_search(s, rel_tbl, checked).index(t)
    puts "yes"
  else
    puts "no"
  end
}