let () =
  let (n, m) = Scanf.scanf "%d %d\n" (fun n m -> (n, m)) in
  let v = Array.make n (-1) in
  let g = Array.make n [] in
  let rec read i =
    if i < m then begin
      let (s, t) = Scanf.scanf "%d %d\n" (fun s t -> (s, t)) in
      g.(s) <- t :: g.(s);
      g.(t) <- s :: g.(t);
      read (i + 1)
    end
  in
  read 0;
  let rec dudu j = function
    | [] -> ()
    | hd :: tl when v.(hd) = (-1) -> (wa hd j; dudu j tl)
    | _ :: tl -> dudu j tl
  and wa i j = v.(i) <- j; dudu j g.(i)
  and doit i =
    if i < n then (if v.(i) = (-1) then wa i i; doit (i + 1))
  in
  doit 0;
  let q = Scanf.scanf "%d\n" (fun q -> q) in
  let rec read_q i =
    if i < q then begin
      let (s, t) = Scanf.scanf "%d %d\n" (fun s t -> (s, t)) in
      print_endline (if v.(s) = v.(t) then "yes" else "no");
      read_q (i + 1)
    end
  in
  read_q 0