# Node
class Node
  attr_accessor :id, :edges, :visited

  def initialize(id, edges = [], visited = false)
    @id, @edges, @visited = id, edges, visited
  end
end

# Edge
class Edge
  attr_accessor :to

  def initialize(to)
    @to = to
  end
end

# Graph
class Graph
  attr_accessor :nodes

  def initialize(data)
    @nodes = data.each_with_object({}) do |(id, edges), hash|
      edges.map! { |edge| Edge.new(*edge) }
      hash[id] = Node.new(id, edges)
    end
  end

  def connected?(s, t)
    @nodes.each do |id, node|
      node.visited = false
    end

    queue = [@nodes[s]]

    while queue.any?
      node = queue.shift
      node.visited = true
      node.edges.each do |edge|
        id = edge.to
        visited_node = @nodes[id]
        return true if visited_node.id == t
        queue << visited_node unless visited_node.visited
      end
    end

    false
  end
end

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

data = {}

n.times do |i|
  data[i] = []
end

m.times do
  s, t = gets.chop.split.map(&:to_i)
  data[s] << t
  data[t] << s
end

g = Graph.new data

q = gets.chop.to_i

q.times do
  puts (g.connected?(*gets.chop.split.map(&:to_i))) ? 'yes' : 'no'
end