class Node
  def initialize(id)
    @id = id
    @friends = []
    @visited = false
  end

  attr_accessor :id, :friends, :visited
end

def input_pair(id1, id2, pool)
  me = pool[id1]
  other = pool[id2]
  me = pool[id1] = Node.new(id1) if me == nil
  other = pool[id2] = Node.new(id2) if other == nil

  me.friends << id2
  other.friends << id1
end

def visit(current, target, pool)
  pool[current].visited = true
  if (current == target) then
    return true
  end

  unvisit_friends = 
    pool[current].friends.select {|item| pool[item].visited == false}

  if (unvisit_friends.size == 0) then
    return false
  end

  return unvisit_friends.any? do |item|
    visit(item, target, pool)
  end
end


# main
n, m = gets.chomp.split.map(&:to_i)
pool = {}
(n).times do |i|
  pool[i] = Node.new(i)
end
(m).times do
  inputs = gets.chomp.split.map(&:to_i)
  input_pair(inputs[0], inputs[1], pool)
end

(gets.chomp.to_i).times do 
  inputs = gets.chomp.split.map(&:to_i)
  puts "#{visit(inputs[0], inputs[1], pool) ? "yes" : "no"}"
end