{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import Data.Array.Unboxed
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]
            | (sarr ! b - sarr ! (a - 1)) `mod` 3 == (tarr ! d - tarr ! (c - 1)) `mod` 3 = "YES"
            | otherwise = "NO"
        sarr = build ss
        tarr = build ts


build :: B.ByteString -> UArray Int Int
build bs = array (0, n) xs
    where
        (xs, n) = fst $ B.foldl' ff (([(0, 0)], 1), 0) bs
        ff ((ys, i), acc) b = (((i, next) : ys, i + 1), next)
            where
                next = acc + ord b - ord 'A' + 1

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)
