import Control.Applicative ((<$>))
import Control.Monad (forM_)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (unfoldr)
import Data.Char (isSpace)
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V
import Data.Vector.Mutable (IOVector)
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  [n, m] <- readil B.readInt <$> B.getLine
  solve n m

solve :: Int -> Int -> IO ()
solve n m = do
  gd <- VM.replicate n []
  forM_ [1..m] $ \_ -> do
    [u, v] <- readil B.readInt <$> B.getLine
    ul <- VM.read gd u
    VM.write gd u (v:ul)
    vl <- VM.read gd v
    VM.write gd v (u:vl)
  q <- readi B.readInt <$> B.getLine
  forM_ [1..q] $ \_ -> do
    [s, t] <- readil B.readInt <$> B.getLine
    friend gd s t >>= putStrLn
  where friend :: IOVector [Int] -> Int -> Int -> IO String
        friend gd s t = do
          cl <- VM.replicate n W
          VM.write cl s B
          dfs cl [s]
          where dfs :: IOVector Color -> [Int] -> IO String
                dfs cl [] = return "no"
                dfs cl (u:st) = do
                  nbl <- VM.read gd u
                  mv <- findM (\j -> do
                                  c <- VM.read cl j
                                  return (c == W)) nbl
                  case mv of
                   (Just v) -> if v == t then return "yes"
                               else do
                                 VM.write cl v B
                                 dfs cl (v:u:st)
                   Nothing -> dfs cl st

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')

data Color = W | B deriving (Show, Eq, Ord)

findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
findM p [] = return Nothing
findM p (x:xs) = do
  b <- p x
  if b then return $ Just x
    else findM p xs

