import scala.collection.mutable
import scala.io.StdIn._

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

object Main extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val group: mutable.Seq[Int] = mutable.Seq.fill(n)(-1)
  var edges: Set[Edge] = Set()

  for (i <- 1 to m) {
    val Array(v1, v2) = readLine().split(" ").map(_.toInt)
    edges += Edge(v1, v2)
  }

  var id = 0
  while (edges.nonEmpty) {
    crawl(edges.head, id)
    id += 1
  }

  for (i <- 1 to readInt()) {
    val Array(v1, v2) = readLine().split(" ").map(_.toInt)
    if (group(v1) != -1 && group(v1) == group(v2)) println("yes") else println("no")
  }

  def crawl(edge: Edge, id: Int): Unit = {
    val que = mutable.Queue(edge)
    while (que.nonEmpty) {
      val e1 = que.dequeue()
      group(e1.to) = id
      group(e1.from) = id
      edges -= e1
      edges.foreach(e => {
        if (e.from == e1.from || e.to == e1.from || e.from == e1.to || e.to == e1.to)
          que.enqueue(e)
      })
    }
  }
}