#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String);
    let t = get!(String);
    let q = get!(usize);
    let abcd = get!(usize, usize, usize, usize;q);

    let mut sums = vec![(0isize,0isize); s.len()+1];
    let mut sumt = vec![(0isize,0isize); t.len()+1];

    for (i, c) in s.chars().enumerate() {
        sums[i+1] = if c == 'A' {
            (sums[i].0+1, sums[i].1)
        } else {
            (sums[i].0, sums[i].1+1)
        };
    }
    for (i, c) in t.chars().enumerate() {
        sumt[i+1] = if c == 'A' {
            (sumt[i].0+1, sumt[i].1)
        } else {
            (sumt[i].0, sumt[i].1+1)
        };
    }

    for (a,b,c,d) in abcd {
        let sa = sums[b].0-sums[a-1].0;
        let sb = sums[b].1-sums[a-1].1;
        let ta = sumt[d].0-sumt[c-1].0;
        let tb = sumt[d].1-sumt[c-1].1;

        let da = ta-sa;
        let db = tb-sb;

        let ra = if da%3 < 0 {
            da%3+3
        } else {
            da%3
        };
        let rb = if db%3 < 0 {
            db%3+3
        } else {
            db%3
        };

        if ra == rb {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


Measured memory_bytes: 17020