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 n (concat ns) qs

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

solve :: Int -> [(Int, Int)] -> [(Int, Int)] -> [String]
solve n graph query = runST $ do
  uf <- makeUF n graph
  ans' <- mapM (hasSamePar' uf) query
  let ans = map (\b ->
                   if b then "yes" else "no") ans'
  return ans

makeUF n graph = do
  res <- newArray (0, n-1) 0 :: ST s (STUFTree s)
  forM_ [0..n-1] (\i -> writeArray res i i)
  forM_ graph (upd res)
  return 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' :: (Show e, MArray a e m, Ix e)
               => a e e -> (e, e) -> m Bool
hasSamePar' arr (x, y) = do
  parX <- findParent arr x
  parY <- findParent arr y
  return (parX == parY)