import Control.Monad
import Data.Array
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 (0, length x) . zip [0..] . (0: ) $ cvt 0 x
        cvt n (x : xs)
            | x == 'A' = 1 + n : cvt (1 + n) xs
            | otherwise = 2 + n : cvt (2 + n) xs
        cvt _ _ = []

solve :: Array Int Int -> Array Int Int -> [[Int]] -> [String]
solve s t = fmap mapf
    where
        mapf [a, b, c, d]
            | (s ! b - s ! (a - 1)) `mod` 3 == (t ! d - t ! (c - 1)) `mod` 3 = "YES"
            | otherwise = "NO"
