class DisjointSet
  attr_reader :parent, :rank

  def initialize(ids = [])
    @parent, @rank = {}, {}
    ids.each do |id|
      @parent[id] = id
      @rank[id] = 0
    end
  end

  def make_set(x)
    @parent[x] = x
    @rank[x] = 0
  end

  def find(x)
    return x if (@parent[x] == x)
    @parent[x] = find(@parent[x])
    @parent[x]
  end

  def union(x, y)
    root_x, root_y, rank_x, rank_y =
      find(x), find(y), @rank[x], @rank[y]

    return if (root_x == root_y)

    if (rank_x > rank_y)
      @parent[y] = root_x
    elsif (rank_x < rank_y)
      @parent[x] = root_y
    else
      @parent[y] = root_x
      @rank[x] += 1
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end
end

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

g = DisjointSet.new

n.times do |i|
  g.make_set i
end

m.times do
  g.union *gets.chop.split.map(&:to_i)
end

q = gets.chop.to_i

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