import Control.Monad
import Data.Array
import Data.List
main = replicateM 2 getLine >>= main'
    where
        main' [s, t] = readLn >>= flip replicateM getLine >>= mapM_ putStrLn . solve (toArr s) (toArr t) . fmap (fmap read . words)
        toArr x = array (1, length x) $ zip [1..] x

solve :: Array Int Char -> Array Int Char -> [[Int]] -> [String]
solve s t ([a, b, c, d] : xs) = res : solve s t xs
    where
        cvt arr = (`mod` 3) . foldl' ff 0
            where
                ff acc x
                    | arr ! x == 'A' = 1 + acc
                    | otherwise = 2 + acc

        res
            | cvt s [a..b] == cvt t [c..d] = "YES"
            | otherwise = "NO"

solve _ _ _ = []
