{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as B
main = replicateM 2 B.getLine >>= main'
    where
        main' [s, t] = readLn >>= flip replicateM breadIs >>= mapM_ B.putStrLn . solve s t

solve :: B.ByteString -> B.ByteString -> [[Int]] -> [B.ByteString]
solve ss ts = fmap mapf
    where
        mapf [a, b, c, d]
            | calc s == calc t = "YES"
            | otherwise = "NO"
            where
                s = B.drop (a - 1) . B.take b $ ss
                t = B.drop (c - 1) . B.take d $ ts

calc :: B.ByteString -> Int
calc = B.foldl' (\acc x -> (acc + ord x - ord 'A' + 1) `mod` 3) 0

breadIs :: IO [Int]
breadIs = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)
