import Control.Monad (replicateM)

main :: IO ()
main = do
    s <- getLine
    t <- getLine
    n <- readLn
    qs <- replicateM n $ do
        q <- getLine
        return $ map read $ words q
    mapM_ (putStrLn . solve s t) qs

solve :: String -> String -> [Int] -> String
solve s t [x0,x1,y0,y1] = if match s' t' then "YES" else "NO"
    where s' = substr x0 x1 s
          t' = substr y0 y1 t

substr :: Int -> Int -> String -> String
substr x0 x1 = drop (x0-1) . take x1

match :: String -> String -> Bool
match s t = reduce s == reduce t

reduce :: String -> String
reduce "" = ""
reduce "A" = "A"
reduce "B" = "B"
reduce ('A':'A':'A':s) = reduce s
reduce ('B':'B':'B':s) = reduce s
reduce ('A':'B':s) = reduce s
reduce ('B':'A':s) = reduce s
reduce ('A':'A':s) = reduce $ 'B':s
reduce ('B':'B':s) = reduce $ 'A':s
