import scala.io.StdIn._

case class Edge(from: Int, to: Int)

object Main extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  var connected: Seq[Set[Int]] = Seq(Set())

  for (i <- 1 to m) {
    var s: Set[Int] = readLine().split(" ").map(_.toInt).toSet
    connected = connected.foldLeft(Nil: Seq[Set[Int]])((acc, set) => {
      if (set exists (s.contains(_))) {
        s ++= set
        acc
      }
      else set +: acc
    })
    connected :+= s
  }

  for (i <- 1 to readInt()) {
    val Array(f, t) = readLine().split(" ").map(_.toInt)
    if (canReach(f, t)) println("yes") else println("no")
  }

  def canReach(from: Int, to: Int): Boolean = {
    connected exists (s => s.contains(from) && s.contains(to))
  }
}