import scala.io.StdIn.{readLine, readInt};
object Main {
    def main(args: Array[String]): Unit = {
        val Array(n, m) = readLine.split(" ").map(_.toInt);
        val matrix = new Array[List[Int]](n).map( i => List[Int]());
        (0 until m).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(src, dst) => {
                    matrix(src) = dst :: matrix(src);
                    matrix(dst) = src :: matrix(dst);
                }
                case _ => ();
            }
        }
        val group = genGroup(matrix);
        (0 until readInt).foreach { i =>
            val Array(src, dst) = readLine.split(" ").map(_.toInt);
            if (group(src) == group(dst)) println("yes") else println("no");
        }
    }
    
    def genGroup(matrix: Array[List[Int]]): Array[Int] = {
        val len = matrix.length;
        val group = new Array[Int](len);
        def go(que: IntQueue, gid: Int): Unit = {
            que.peek match {
                case None => ();
                case Some(e) => {
                    val nextQue = matrix(e).foldLeft(que.dequeue) { (q, child) =>
                        if (group(child) == 0) {
                            group(child) = gid;
                            q.enqueue(child);
                        } else {
                            q;
                        }
                    }
                    go(nextQue, gid);
                }
            }
        }
        (0 until len).foldLeft(1) { (gid, i) =>
            if (group(i) == 0) {
                group(i) = gid;
                go(IntQueue(i), gid);
                gid + 1;
            } else {
                gid;
            }
        }
        group;
    }
}

class IntQueue(private val addList: List[Int], private val rmList: List[Int]) {
    def peek(): Option[Int] = if (rmList == Nil) None else Some(rmList.head);
    def enqueue(e: Int): IntQueue = {
        if (rmList == Nil) {
            new IntQueue(Nil, (e :: addList).reverse);
        } else {
            new IntQueue(e :: addList, rmList);
        }
    }
    def dequeue(): IntQueue = {
        rmList match {
            case Nil => throw new NoSuchElementException();
            case e :: Nil => new IntQueue(Nil, addList.reverse);
            case e :: es => new IntQueue(addList, rmList.tail);
        }
    }
}
object IntQueue {
    def apply(): IntQueue = new IntQueue(Nil, Nil)
    def apply(es: Int*): IntQueue = new IntQueue(Nil, es.toList);
}
