import Control.Monad
main = replicateM 2 getLine >>= main'
    where
        main' [s, t] = readLn >>= flip replicateM getLine >>= mapM_ putStrLn . solve s t . fmap (fmap read . words)

solve :: String -> String -> [[Int]] -> [String]
solve s t ([a, b, c, d] : xs) = res : solve s t xs
    where
        ps = drop (a - 1) $ take b s
        pt = drop (c - 1) $ take d t

        cvt (y : ys)
            | y == 'A' = 1 + cvt ys
            | otherwise = 2 + cvt ys
        cvt _ = 0

        res
            | cvt ps `mod` 3 == cvt pt `mod` 3 = "YES"
            | otherwise = "NO"

solve _ _ _ = []
