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

  attr_accessor :id, :friends, :visited, :group
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

def grouping!(std_node, pool)
  return if std_node.group != nil

  std_node.group = std_node.id
  group = std_node.group
  stack = [std_node]
  until stack.empty? do
    node = stack.last
    node.group = group
    next_node_id = node.friends.find {|id| pool[id].group == nil}
    if next_node_id == nil then
      stack.pop
    else
      stack.push(pool[next_node_id])
    end
  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

pool.each_value do |node|
  grouping!(node, pool)
end

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