import scala.io.StdIn.{readInt, readLine};
import scala.collection.immutable.Queue;

object Main {
    def main(args: Array[String]): Unit = {
        val info = readLine.split(" ").map(_.toInt);
        val graph: Array[List[Int]] = new Array[List[Int]](info(0)).map(a => Nil);
        for (i <- (0 until info(1))) {
            val c = readLine.split(" ").map(_.toInt);
            graph(c(0)) = c(1) :: graph(c(0));
            graph(c(1)) = c(0) :: graph(c(1));
        }
        val connList: Array[Int] = buildConnectionList(graph);
        for (i <- (0 until readInt)) {
            val q = readLine.split(" ").map(_.toInt);
            if (connList(q(0)) == connList(q(1))) println("yes") else println("no");
        }
    }
    
    def buildConnectionList(graph: Array[List[Int]]): Array[Int] = {
        val size = graph.length;
        val connList = new Array[Int](size);
        def go(que: Queue[Int], group: Int): Int = {
            que.dequeueOption match {
                case None => group + 1;
                case Some((src, restQue)) => {
                    val newQue = graph(src).filter(dst => connList(dst) == 0).foldLeft(restQue) { (q, dst) => 
                        connList(dst) = group; 
                        q.enqueue(dst);
                    }
                    go(newQue, group);
                }
            }
        }
        (0 until size).foldLeft(1) { (group, i) => 
            if (connList(i) == 0) {connList(i) = group;go(Queue(i), group);} else {group}
        }
        connList;
    }
}
