import Control.Monad
import Control.Applicative
import Data.Array.IArray
import Data.Array.ST
import Control.Monad.ST
import Debug.Trace

type Graph = Array Int [Int]
type UFTree = Array Int Int
type STUFTree s = STArray s Int Int

main :: IO ()
main = do
  [n, m] <- getInts
  ns <- replicateM m $ do
    [a, b] <- getInts
    return [(a, b), (b, a)]
  q <- readLn :: IO Int
  qs <- replicateM q $ do
    [a, b] <- getInts
    return (a, b)
  let uf = (makeUF n . concat) ns
--  print uf
  mapM_ putStrLn $ solve uf qs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: UFTree -> [(Int, Int)] -> [String]
solve uf query = map ((\b ->
                          if b then "yes" else "no") .
                       hasSamePar uf) query

makeUF :: Int -> [(Int, Int)] -> UFTree
makeUF n graph = runST $ do
  res <- newArray (0, n-1) 0 :: ST s (STUFTree s)
  forM_ [0..n-1] (\i -> writeArray res i i)
  forM_ graph (upd res)
  freeze res
  where
    upd :: STUFTree s -> (Int, Int) -> ST s ()
    upd res (x, y) = do
      parX <- findParent res x
      parY <- findParent res y
      unless (x == y) $ writeArray res parX parY

findParent :: (Show e, MArray a e m, Ix e) => a e e -> e -> m e
findParent arr x = do
  parX <- readArray arr x
--  trace (show (x, parX)) (return ())
  if parX == x
    then return x
    else do
    parX' <- findParent arr parX
    writeArray arr x parX'
    return parX'

hasSamePar :: UFTree -> (Int, Int) -> Bool
hasSamePar arr (x, y) = parX == parY
  where
    parX = find' x
    parY = find' y
    find' n = let p = arr ! n in
                if n == p
                then n
                else find' p               
    