object Main extends App {
    def find(m: Int, ar: Array[Int]): Int = 
        if(ar(m) == m) m else {ar(m) = find(ar(m), ar); ar(m)}

    def unite(x: Int, y: Int, ar: Array[Int]) = {
        val _x = find(x, ar)
        val _y = find(y, ar)
        if(_x != _y) ar(_x) = _y
    }

    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    for (Array(n, m) <- in) {
        val a = (0 to n-1).toArray
        in.take(m).foreach(r => unite(r(0), r(1), a))
        val s = in.next.head
        in.take(s).foreach(q => println(if (find(q(0), a) == find(q(1), a)) "yes" else "no"))
    }
}