{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import qualified Data.IntMap.Strict    as M

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

dfs :: (Int, Int) -> Array Int [Int] -> Bool
dfs (s, t) g = go (M.empty :: M.IntMap ()) s
  where
    go !m v
        | v == t    = True
        | otherwise = or $ fmap (go m') ws
      where
        ws = filter (flip M.notMember m) (g ! v)
        m' = foldr (\w ac -> M.insert w () ac) m ws

main :: IO ()
main = do
    [n, m] <- fmap readi . B.words <$> B.getLine
    mss <-
        accumArray (flip (:)) [] (0, n - 1) .
        fmap ((\[a, b] -> (a, b)) . fmap readi . B.words) <$>
        replicateM m B.getLine :: IO (Array Int [Int])
    q <- readi <$> B.getLine
    qss <- fmap (fmap readi . B.words) <$> replicateM q B.getLine

    forM_ qss $ \[s, t] ->
        if dfs (s, t) mss
            then putStrLn "yes"
            else putStrLn "no"

