import scala.io.StdIn.{readInt, readLine};
import scala.collection.immutable.HashMap;
import scala.annotation.tailrec;

object Main {
    def main(args: Array[String]): Unit = {
        val relations = readLine.split(" ").map(_.toInt).last;
        val g = (0 until relations).foldLeft(Graph[Int]()) { (graph, i) =>
            readLine.split(" ").map(_.toInt) match {
                case Array(src, dst) => graph.add(src, dst);
                case _ => graph;
            }
        }
        val groups = g.dfs;
        (0 until readInt).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(n1, n2) => {
                    if (groups.contains(n1) && 
                         groups.contains(n2) && 
                         groups.get(n1) == groups.get(n2)) {
                        println("yes");
                    } else {
                        println("no");
                    }
                }
            }
        }
        
    }
}
case class Graph[A](graph: HashMap[A, List[A]]) {
    def dump: Unit = graph.foreach { e => println("%d -> %s".format(e._1, e._2.mkString(" ")))}

    def add(n1: A, n2: A): Graph[A] = {
        val n1Value = n2 :: graph.getOrElse(n1, Nil)
        val n2Value = n1 :: graph.getOrElse(n2, Nil);
        new Graph[A](graph.updated(n1, n1Value).updated(n2, n2Value));
    }
    
    def dfs: HashMap[A, Int] = {
        @tailrec
        def go(stack: List[A], visited: HashMap[A, Int], group: Int): HashMap[A, Int] = stack.headOption match {
            case None => visited;
            case Some(curr) => {
                val nextNodes = graph.getOrElse(curr, Nil).filter(!visited.contains(_));
                go(nextNodes ::: stack.tail, visited.updated(curr, group), group);
            }
        }
        var cnt = 0;
        graph.keys.foldLeft(HashMap[A, Int]()) { (gList, node) =>
            if (!gList.contains(node)) {
                cnt += 1;
                go(List[A](node), gList.updated(node, cnt), cnt);
            } else {
                gList;
            }
        }
    }
}
object Graph {
    def apply[A](): Graph[A] = new Graph(HashMap[A, List[A]]());
}
