AtCoder Regular Contest 071 - TrBBnsformBBtion

Let us consider the following operations on a string consisting of A and B:
 - Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA.
 - Select a substring that is equal to either AAA or BBB, and delete it from the string.
For example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA.
If the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries a_i, b_i, c_i, d_i.
For each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S, can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T.

-----Constraints-----
 - 1 \leq |S|, |T| \leq 10^5
 - S and T consist of letters A and B.
 - 1 \leq q \leq 10^5
 - 1 \leq a_i \leq b_i \leq |S|
 - 1 \leq c_i \leq d_i \leq |T|

-----Input-----
Input is given from Standard Input in the following format:
S
T
q
a_1 b_1 c_1 d_1
...
a_q b_q c_q d_q

-----Output-----
Print q lines. The i-th line should contain the response to the i-th query. If S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, print YES. Otherwise, print NO.

-----Sample Input-----
BBBAAAABA
BBBBA
4
7 9 2 5
7 9 1 4
1 7 2 5
1 7 2 4

-----Sample Output-----
YES
NO
YES
NO

The first query asks whether the string ABA can be made into BBBA.
As explained in the problem statement, it can be done by the first operation.
The second query asks whether ABA can be made into BBBB, and the fourth query asks whether BBBAAAA can be made into BBB.
Neither is possible.
The third query asks whether the string BBBAAAA can be made into BBBA.
As explained in the problem statement, it can be done by the second operation.

Source: atcoder | Difficulty: HARD


Solutions:
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

def main():
	S = list(input())
	N = len(S)
	s = [0] * (N + 1)
	for i in range(N):
		if S[i] == 'A':
			s[i + 1] += s[i] + 2
		else:
			s[i + 1] += s[i] + 1
	T = list(input())
	M = len(T)
	t = [0] * (M + 1)
	for i in range(M):
		if T[i] == 'A':
			t[i + 1] += t[i] + 2
		else:
			t[i + 1] += t[i] + 1
	Q = int(input())
	for i in range(Q):
		(a, b, c, d) = getlist()
		if (s[b] - s[a - 1] - (t[d] - t[c - 1])) % 3 == 0:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline()[:-1]
mod = 10 ** 9 + 7

def I():
	return int(input())

def LI():
	return list(map(int, input().split()))

def LIR(row, col):
	if row <= 0:
		return [[] for _ in range(col)]
	elif col == 1:
		return [I() for _ in range(row)]
	else:
		read_all = [LI() for _ in range(row)]
		return map(list, zip(*read_all))
S = list(input())
T = list(input())
q = I()
(a, b, c, d) = LIR(q, 4)
n = len(S)
Sab = [0] * (n + 1)
for i in range(n):
	if S[i] == 'A':
		Sab[i + 1] = Sab[i] + 1
	else:
		Sab[i + 1] = Sab[i] - 1
m = len(T)
Tab = [0] * (m + 1)
for i in range(m):
	if T[i] == 'A':
		Tab[i + 1] = Tab[i] + 1
	else:
		Tab[i + 1] = Tab[i] - 1
for i in range(q):
	diff = Sab[b[i]] - Sab[a[i] - 1] - (Tab[d[i]] - Tab[c[i] - 1])
	if diff % 3 == 0:
		print('YES')
	else:
		print('NO')


def examC():
	N = I()
	d = defaultdict(int)
	for i in range(N):
		curD = defaultdict(int)
		S = SI()
		for s in S:
			curD[s] += 1
		if i == 0:
			d = curD
			continue
		for s in alphabet:
			d[s] = min(d[s], curD[s])
	d = sorted(d.items())
	ans = ''
	for (key, i) in d:
		ans += key * i
	print(ans)
	return

def examD():
	(N, M) = LI()
	X = LI()
	Y = LI()
	distX = [0] * N
	distY = [0] * M
	for i in range(N - 1):
		distX[i + 1] = X[i + 1] - X[i]
	for i in range(M - 1):
		distY[i + 1] = Y[i + 1] - Y[i]
	numX = [0] * N
	numY = [0] * M
	for i in range(N):
		numX[i] = i * (N - i)
	for i in range(M):
		numY[i] = i * (M - i)
	LX = 0
	LY = 0
	for i in range(N):
		LX += distX[i] * numX[i]
		LX %= mod
	for i in range(M):
		LY += distY[i] * numY[i]
		LY %= mod
	ans = LX * LY % mod
	print(ans)
	return

def examE():
	S = SI()
	T = SI()
	numaS = [0] * (len(S) + 1)
	numaT = [0] * (len(T) + 1)
	for (i, s) in enumerate(S):
		numaS[i + 1] = numaS[i]
		if s == 'A':
			numaS[i + 1] += 1
	for (i, s) in enumerate(T):
		numaT[i + 1] = numaT[i]
		if s == 'A':
			numaT[i + 1] += 1
	Q = I()
	ans = ['YES'] * Q
	for i in range(Q):
		(a, b, c, d) = LI()
		curaS = numaS[b] - numaS[a - 1]
		curbS = b - a - curaS + 1
		curaT = numaT[d] - numaT[c - 1]
		curbT = d - c - curaT + 1
		if (curaS % 3 + (curaS + curbS) % 3) % 3 != (curaT % 3 + (curaT + curbT) % 3) % 3:
			ans[i] = 'NO'
	for v in ans:
		print(v)
	return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
alphabet = [chr(ord('a') + i) for i in range(26)]
examE()


(S, T) = ([0], [0])
for (k, c) in enumerate(input()):
	S += [S[-1] + (c == 'A')]
for (k, c) in enumerate(input()):
	T += [T[-1] + (c == 'A')]
for _ in [0] * int(input()):
	(a, b, c, d) = map(int, input().split())
	print(['YES', 'NO'][(2 * (b - a - d + c) + T[d] - T[c - 1] - S[b] + S[a - 1]) % 3 > 0])


s = input().strip()
t = input().strip()
csa = [0]
csb = [0]
for ch in s:
	if ch == 'A':
		csa.append(csa[-1] + 1)
		csb.append(csb[-1])
	else:
		csa.append(csa[-1])
		csb.append(csb[-1] + 1)
cta = [0]
ctb = [0]
for ch in t:
	if ch == 'A':
		cta.append(cta[-1] + 1)
		ctb.append(ctb[-1])
	else:
		cta.append(cta[-1])
		ctb.append(ctb[-1] + 1)
Q = int(input())
for q in range(Q):
	(a, b, c, d) = map(int, input().split())
	sa = csa[b] - csa[a - 1]
	sb = csb[b] - csb[a - 1]
	ta = cta[d] - cta[c - 1]
	tb = ctb[d] - ctb[c - 1]
	if (sa - sb + tb - ta) % 3:
		print('NO')
	else:
		print('YES')


import sys
readline = sys.stdin.readline
S = readline().rstrip()
T = readline().rstrip()
q = int(readline())
Sa = [0] * (len(S) + 1)
Sb = [0] * (len(S) + 1)
Ta = [0] * (len(T) + 1)
Tb = [0] * (len(T) + 1)
for i in range(len(S)):
	if S[i] == 'A':
		Sa[i + 1] = 1
	else:
		Sb[i + 1] = 1
for i in range(len(S)):
	Sa[i + 1] += Sa[i]
	Sb[i + 1] += Sb[i]
for i in range(len(T)):
	if T[i] == 'A':
		Ta[i + 1] = 1
	else:
		Tb[i + 1] = 1
for i in range(len(T)):
	Ta[i + 1] += Ta[i]
	Tb[i + 1] += Tb[i]
ok_group = {((0, 1), (2, 0), (1, 2)), ((0, 2), (2, 1), (1, 0)), ((1, 1), (0, 0), (2, 2))}
for i in range(q):
	(a, b, c, d) = list(map(int, readline().split()))
	s = ((Sa[b] - Sa[a - 1]) % 3, (Sb[b] - Sb[a - 1]) % 3)
	t = ((Ta[d] - Ta[c - 1]) % 3, (Tb[d] - Tb[c - 1]) % 3)
	if s == t:
		print('YES')
		continue
	for ok in ok_group:
		if s in ok and t in ok:
			print('YES')
			break
	else:
		print('NO')


s = list(input())
t = list(input())
(ls, lt) = (len(s), len(t))
(sa, sb) = ([0] * (ls + 1), [0] * (ls + 1))
(ta, tb) = ([0] * (lt + 1), [0] * (lt + 1))
for i in range(1, ls + 1):
	if s[i - 1] == 'A':
		sa[i] = sa[i - 1] + 1
		sb[i] = sb[i - 1]
	else:
		sa[i] = sa[i - 1]
		sb[i] = sb[i - 1] + 1
for i in range(1, lt + 1):
	if t[i - 1] == 'A':
		ta[i] = ta[i - 1] + 1
		tb[i] = tb[i - 1]
	else:
		ta[i] = ta[i - 1]
		tb[i] = tb[i - 1] + 1
q = int(input())
for _ in range(q):
	ans = 0
	(a, b, c, d) = map(int, input().split())
	(a1, b1) = (sa[b] - sa[a - 1], sb[b] - sb[a - 1])
	(a2, b2) = (ta[d] - ta[c - 1], tb[d] - tb[c - 1])
	(x, y) = (a1 - b1, a2 - b2)
	if x * y < 0:
		x = -2 * x
	if abs(x - y) % 3 == 0:
		ans = 1
	print('YES' if ans == 1 else 'NO')


def main():
	s = input()
	t = input()
	a = [0] * (len(s) + 1)
	b = [0] * (len(t) + 1)
	for (i, c) in enumerate(s):
		if c == 'A':
			a[i + 1] = 1
		else:
			a[i + 1] = 2
		a[i + 1] += a[i]
	for (i, c) in enumerate(t):
		if c == 'A':
			b[i + 1] = 1
		else:
			b[i + 1] = 2
		b[i + 1] += b[i]
	q = int(input())
	ans = [None] * q
	for i in range(q):
		(a1, a2, b1, b2) = map(int, input().split())
		(x, y) = (a[a2] - a[a1 - 1], b[b2] - b[b1 - 1])
		if abs(x - y) % 3 == 0:
			ans[i] = 'YES'
		else:
			ans[i] = 'NO'
	for v in ans:
		print(v)

def __starting_point():
	main()
__starting_point()


S = input()
T = input()
sa = [0]
sb = [0]
ta = [0]
tb = [0]
for i in S:
	if i == 'A':
		sa.append(sa[-1] + 1)
		sb.append(sb[-1])
	else:
		sa.append(sa[-1])
		sb.append(sb[-1] + 1)
for i in T:
	if i == 'A':
		ta.append(ta[-1] + 1)
		tb.append(tb[-1])
	else:
		ta.append(ta[-1])
		tb.append(tb[-1] + 1)
q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	one = sa[b] - sa[a - 1] - (sb[b] - sb[a - 1])
	two = ta[d] - ta[c - 1] - (tb[d] - tb[c - 1])
	if one % 3 == two % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
Q = int(input())
ABCD = [list(map(int, input().split())) for _ in [0] * Q]
Si = [0] * (len(S) + 1)
for (i, s) in enumerate(S, 1):
	if s == 'A':
		Si[i] = Si[i - 1] + 1
	else:
		Si[i] = Si[i - 1] + 2
	Si[i] %= 3
Ti = [0] * (len(T) + 1)
for (i, t) in enumerate(T, 1):
	if t == 'A':
		Ti[i] = Ti[i - 1] + 1
	else:
		Ti[i] = Ti[i - 1] + 2
	Ti[i] %= 3
for (a, b, c, d) in ABCD:
	print('YES' if (Si[b] - Si[a - 1]) % 3 == (Ti[d] - Ti[c - 1]) % 3 else 'NO')


def getN():
	return int(input())

def getMN():
	a = input().split()
	b = [int(i) for i in a]
	return (b[0], b[1])

def getlist():
	a = input().split()
	b = [int(i) for i in a]
	return b
astr = input()
bstr = input()
n = getN()
queries = []
for i in range(n):
	queries.append(getlist())
s1 = 1 if astr[0] == 'A' else 2
t1 = 1 if bstr[0] == 'A' else 2
s_acc = [0]
t_acc = [0]
tmp = 0
for s in astr:
	if s == 'A':
		s_acc.append(s_acc[-1] + 1)
	else:
		s_acc.append(s_acc[-1] + 2)
for s in bstr:
	if s == 'A':
		t_acc.append(t_acc[-1] + 1)
	else:
		t_acc.append(t_acc[-1] + 2)
for q in queries:
	(x, y, z, w) = q
	if (s_acc[y] - s_acc[x - 1]) % 3 == (t_acc[w] - t_acc[z - 1]) % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
dps = [0] * len(S)
for i in range(len(S)):
	if S[i] == 'A':
		dps[i] += 1
	if i != 0:
		dps[i] += dps[i - 1]
dpt = [0] * len(T)
for i in range(len(T)):
	if T[i] == 'A':
		dpt[i] += 1
	if i != 0:
		dpt[i] += dpt[i - 1]
dps = [0] + dps
dpt = [0] + dpt
q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	sc = dps[b] - dps[a - 1]
	sa = sc - (b - a + 1 - sc)
	tc = dpt[d] - dpt[c - 1]
	ta = tc - (d - c + 1 - tc)
	if sa % 3 == ta % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
q = int(input())
info = [list(map(int, input().split())) for i in range(q)]
MOD = 3
memo = {'A': 1, 'B': 2}
s_ruiseki = [0] * (len(s) + 1)
for i in range(1, len(s) + 1):
	s_ruiseki[i] = (s_ruiseki[i - 1] + memo[s[i - 1]]) % MOD
t_ruiseki = [0] * (len(t) + 1)
for i in range(1, len(t) + 1):
	t_ruiseki[i] = (t_ruiseki[i - 1] + memo[t[i - 1]]) % MOD
for i in range(q):
	ans1 = (2 * s_ruiseki[info[i][0] - 1] + s_ruiseki[info[i][1]]) % MOD
	ans2 = (2 * t_ruiseki[info[i][2] - 1] + t_ruiseki[info[i][3]]) % MOD
	print('YES' if ans1 == ans2 else 'NO')


s = input()
t = input()
q = int(input())
(ss, tt) = ([0], [0])
for i in range(len(s)):
	ss.append(ss[i] + (1 if s[i] == 'A' else 2))
for i in range(len(t)):
	tt.append(tt[i] + (1 if t[i] == 'A' else 2))
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	s_score = (ss[b] - ss[a - 1]) % 3
	t_score = (tt[d] - tt[c - 1]) % 3
	print('YES' if s_score == t_score else 'NO')


import sys

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def S():
	return sys.stdin.readline().rstrip()
(S, T) = (S(), S())
(a, b) = (0, 0)
accumulate_S = [0]
accumulate_T = [0]
for s in S:
	if s == 'A':
		a += 1
	else:
		a += 2
	accumulate_S.append(a)
for t in T:
	if t == 'A':
		b += 1
	else:
		b += 2
	accumulate_T.append(b)
q = I()
for _ in range(q):
	(a, b, c, d) = MI()
	x = accumulate_S[b] - accumulate_S[a - 1]
	y = accumulate_T[d] - accumulate_T[c - 1]
	if (x - y) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
S = [ord(s) - 65 for s in input()]
T = [ord(t) - 65 for t in input()]
acc1 = [0] + list(accumulate(S))
acc2 = [0] + list(accumulate(T))

def check(cnta, cntb):
	if cnta == cntb:
		return 2
	elif cnta < cntb:
		cntb -= cnta
		if cntb % 3 == 0:
			return 2
		elif cntb % 3 == 1:
			return 1
		else:
			return 0
	else:
		cnta -= cntb
		if cnta % 3 == 0:
			return 2
		elif cnta % 3 == 1:
			return 0
		else:
			return 1
Q = INT()
for _ in range(Q):
	(l1, r1, l2, r2) = MAP()
	ln1 = r1 - l1 + 1
	ln2 = r2 - l2 + 1
	cntb1 = acc1[r1] - acc1[l1 - 1]
	cnta1 = ln1 - cntb1
	cntb2 = acc2[r2] - acc2[l2 - 1]
	cnta2 = ln2 - cntb2
	if check(cnta1, cntb1) == check(cnta2, cntb2):
		YES()
	else:
		NO()


s = input()
t = input()
(n, m) = (len(s), len(t))
a = [0] * (n + 1)
b = [0] * (m + 1)
for i in range(n):
	a[i + 1] = a[i]
	if s[i] == 'A':
		a[i + 1] += 1
	else:
		a[i + 1] += 2
for i in range(m):
	b[i + 1] = b[i]
	if t[i] == 'A':
		b[i + 1] += 1
	else:
		b[i + 1] += 2
q = int(input())
for _ in range(q):
	(i, j, k, l) = list(map(int, input().split()))
	if (a[j] - a[i - 1]) % 3 == (b[l] - b[k - 1]) % 3:
		print('YES')
	else:
		print('NO')


from operator import add
import sys
input = sys.stdin.readline

class SegTree:

	def __init__(self, N, e, operator_func=add):
		self.e = e
		self.size = N
		self.node = [self.e] * (2 * N)
		self.operator_func = operator_func

	def set_list(self, l):
		for i in range(self.size):
			self.node[i + self.size - 1] = l[i]
		for i in range(self.size - 1)[::-1]:
			self.node[i] = self.operator_func(self.node[2 * i + 1], self.node[2 * i + 2])

	def update(self, k, x):
		k += self.size - 1
		self.node[k] = x
		while k >= 0:
			k = (k - 1) // 2
			self.node[k] = self.operator_func(self.node[2 * k + 1], self.node[2 * k + 2])

	def get(self, l, r):
		x = self.e
		l += self.size
		r += self.size
		while l < r:
			if l & 1:
				x = self.operator_func(x, self.node[l - 1])
				l += 1
			if r & 1:
				r -= 1
				x = self.operator_func(x, self.node[r - 1])
			l >>= 1
			r >>= 1
		return x

def main():
	S = input()
	T = input()
	treeS = SegTree(len(S), 0)
	treeT = SegTree(len(T), 0)
	treeS.set_list([1 if s == 'A' else 0 for s in S])
	treeT.set_list([1 if s == 'A' else 0 for s in T])
	q = int(input())
	for _ in range(q):
		(a, b, c, d) = map(int, input().split())
		sa = treeS.get(a - 1, b)
		sb = b - a + 1 - sa
		ta = treeT.get(c - 1, d)
		tb = d - c + 1 - ta
		if (2 * (sb - sa) + tb - ta) % 3 or (sb - sa + 2 * (tb - ta)) % 3:
			print('NO')
		else:
			print('YES')
main()


(S, T) = (input(), input())
q = int(input())
(ls, lt) = (len(S), len(T))
(acs, act) = ([0] * (ls + 1), [0] * (lt + 1))
for i in range(1, ls + 1):
	acs[i] = acs[i - 1] + (S[i - 1] == 'A')
for i in range(1, lt + 1):
	act[i] = act[i - 1] + (T[i - 1] == 'A')
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	print('YES' if (acs[b] - acs[a - 1] + b - a + 1) % 3 == (act[d] - act[c - 1] + d - c + 1) % 3 else 'NO')


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(S, T, ABCD):
	S_ = [0]
	for c in S:
		S_.append((1 if c == 'A' else 2) + S_[-1])
	T_ = [0]
	for c in T:
		T_.append((1 if c == 'A' else 2) + T_[-1])
	for (a, b, c, d) in ABCD:
		s = (S_[b] - S_[a - 1]) % 3
		t = (T_[d] - T_[c - 1]) % 3
		if s == t:
			print('YES')
		else:
			print('NO')

def main():
	S = read_str()
	T = read_str()
	q = read_int()
	ABCD = [read_int_n() for _ in range(q)]
	slv(S, T, ABCD)
main()


from itertools import accumulate
s = list(input().replace('A', '1').replace('B', '2'))
t = list(input().replace('A', '1').replace('B', '2'))
s = list(map(int, s))
t = list(map(int, t))
accs = [0] + list(accumulate(s))
acct = [0] + list(accumulate(t))
q = int(input())
abcd = [list(map(int, input().split())) for i in range(q)]
for (a, b, c, d) in abcd:
	if (accs[b] - accs[a - 1]) % 3 == (acct[d] - acct[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
(S, T) = ([0], [0])
for i in range(len(s)):
	if s[i] == 'A':
		S.append((S[-1] + 1) % 3)
	elif s[i] == 'B':
		S.append((S[-1] + 2) % 3)
for i in range(len(t)):
	if t[i] == 'A':
		T.append((T[-1] + 1) % 3)
	elif t[i] == 'B':
		T.append((T[-1] + 2) % 3)
Q = int(input())
for q in range(Q):
	(a, b, c, d) = map(int, input().split())
	if (S[b] - S[a - 1]) % 3 == (T[d] - T[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import sys
cin = sys.stdin
S = cin.readline().strip()
T = cin.readline().strip()
q = int(cin.readline())

def ABcnt(S):
	ls = len(S)
	cnt = 0
	Rcnt = [0] * (ls + 1)
	for i in range(ls):
		if S[i] == 'A':
			cnt += 1
		else:
			cnt -= 1
		Rcnt[i + 1] = cnt
	return Rcnt
Scnt = ABcnt(S)
Tcnt = ABcnt(T)
for i in range(q):
	(a, b, c, d) = map(int, cin.readline().split())
	Stotal = (Scnt[b] - Scnt[a - 1]) % 3
	Ttotal = (Tcnt[d] - Tcnt[c - 1]) % 3
	if Stotal == Ttotal:
		print('YES')
	else:
		print('NO')


def cumsum_a(st):
	cs = [0] * len(st)
	for (i, s) in enumerate(st):
		if s == 'A':
			cs[i] = 1
		if i > 0:
			cs[i] += cs[i - 1]
	return cs

def main():
	S = input()
	T = input()
	Q = int(input())
	query_list = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(Q)]
	(s_cs_a, t_cs_a) = (cumsum_a(S), cumsum_a(T))
	for query in query_list:
		(s_left, s_right, t_left, t_right) = query
		s_count_a = s_cs_a[s_right]
		if s_left > 0:
			s_count_a -= s_cs_a[s_left - 1]
		s_count_b = s_right - s_left + 1 - s_count_a
		t_count_a = t_cs_a[t_right]
		if t_left > 0:
			t_count_a -= t_cs_a[t_left - 1]
		t_count_b = t_right - t_left + 1 - t_count_a
		s_diff = (s_count_a - s_count_b) % 3
		t_diff = (t_count_a - t_count_b) % 3
		if s_diff == t_diff:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


(NONE_RES, A_RES, B_RES) = (0, 1, 2)
buf = [[NONE_RES, B_RES, A_RES], [A_RES, NONE_RES, B_RES], [B_RES, A_RES, NONE_RES]]
S = input()
s = [1 if c == 'A' else 0 for c in S]
T = input()
t = [1 if c == 'A' else 0 for c in T]
n = int(input())
sum_s = [0]
for s_ in s:
	sum_s.append(sum_s[-1] + s_)
sum_t = [0]
for t_ in t:
	sum_t.append(sum_t[-1] + t_)
for _ in range(n):
	(a, b, c, d) = map(int, input().split(' '))
	A1 = sum_s[b] - sum_s[a - 1]
	B1 = b - (a - 1) - A1
	A2 = sum_t[d] - sum_t[c - 1]
	B2 = d - (c - 1) - A2
	type1 = buf[A1 % 3][B1 % 3]
	type2 = buf[A2 % 3][B2 % 3]
	if type1 == type2:
		print('YES')
	else:
		print('NO')


from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
from heapq import *

def read():
	return int(input())

def reads():
	return [int(x) for x in input().split()]

def enc(s):
	return [1 if c == 'A' else 2 for c in s]
S = enc(input())
T = enc(input())
psumS = [0] + list(accumulate(S))
psumT = [0] + list(accumulate(T))
q = read()
for _ in range(q):
	(a, b, c, d) = reads()
	ms = psumS[b] - psumS[a - 1]
	mt = psumT[d] - psumT[c - 1]
	ans = (ms - mt) % 3 == 0
	print('YES' if ans else 'NO')


import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

def input():
	return sys.stdin.readline()[:-1]

def ruiseki(lst):
	return [0] + list(accumulate(lst))

def celi(a, b):
	return -(-a // b)
sys.setrecursionlimit(5000000)
mod = pow(10, 9) + 7
al = [chr(ord('a') + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
(s, t) = (input(), input())
q = int(input())
abcd = [list(map(int, input().split())) for i in range(q)]
scnt = [(0, 0)] * (len(s) + 1)
tcnt = [(0, 0)] * (len(t) + 1)
for i in range(len(s)):
	(a, b) = scnt[i]
	if s[i] == 'A':
		a += 1
	else:
		b += 1
	scnt[i + 1] = (a, b)
for i in range(len(t)):
	(a, b) = tcnt[i]
	if t[i] == 'A':
		a += 1
	else:
		b += 1
	tcnt[i + 1] = (a, b)
for i in range(q):
	(a, b, c, d) = abcd[i]
	(sa, sb) = (scnt[b], scnt[a - 1])
	(sa, sb) = (sa[0] - sb[0], sa[1] - sb[1])
	(ta, tb) = (tcnt[d], tcnt[c - 1])
	(ta, tb) = (ta[0] - tb[0], ta[1] - tb[1])
	if abs(sa - sb - (ta - tb)) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
S = '-' + sr()
T = '-' + sr()
Q = ir()
cnt_S = np.array([[0, 0] for _ in range(len(S))])
cnt_T = np.array([[0, 0] for _ in range(len(S))])
for (i, s) in enumerate(S[1:], 1):
	if s == 'A':
		cnt_S[i][0] = 1
	else:
		cnt_S[i][1] = 1
for (i, t) in enumerate(T[1:], 1):
	if t == 'A':
		cnt_T[i][0] = 1
	else:
		cnt_T[i][1] = 1
np.add.accumulate(cnt_S, axis=0, out=cnt_S)
np.add.accumulate(cnt_T, axis=0, out=cnt_T)
for _ in range(Q):
	(a, b, c, d) = lr()
	num_S = cnt_S[b][0] - cnt_S[b][1] - (cnt_S[a - 1][0] - cnt_S[a - 1][1])
	num_T = cnt_T[d][0] - cnt_T[d][1] - (cnt_T[c - 1][0] - cnt_T[c - 1][1])
	if (num_S - num_T) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
n = len(S)
m = len(T)
L = [0] * (n + 1)
R = [0] * (m + 1)
for (i, s) in enumerate(S):
	if s == 'A':
		L[i + 1] = (L[i] + 1) % 3
	else:
		L[i + 1] = (L[i] - 1) % 3
for (i, t) in enumerate(T):
	if t == 'A':
		R[i + 1] = (R[i] + 1) % 3
	else:
		R[i + 1] = (R[i] - 1) % 3
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if (L[b] - L[a - 1]) % 3 == (R[d] - R[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
import sys
input = sys.stdin.readline
S = input()
T = input()
cntS = [1 if S[i] == 'A' else -1 for i in range(len(S))]
cntT = [1 if T[i] == 'A' else -1 for i in range(len(T))]
cumS = list(accumulate([0] + cntS))
cumT = list(accumulate([0] + cntT))
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if (cumS[b] - cumS[a - 1]) % 3 == (cumT[d] - cumT[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


from fractions import gcd
from heapq import *
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
MOD = 10 ** 9 + 7

def main():
	s = input()
	t = input()
	q = int(input())
	sa = [0] * (len(s) + 1)
	sb = [0] * (len(s) + 1)
	ta = [0] * (len(t) + 1)
	tb = [0] * (len(t) + 1)
	for i in range(1, len(s) + 1):
		if s[i - 1] == 'A':
			sa[i] = sa[i - 1] + 1
		else:
			sa[i] = sa[i - 1]
		if s[i - 1] == 'B':
			sb[i] = sb[i - 1] + 1
		else:
			sb[i] = sb[i - 1]
	for i in range(1, len(t) + 1):
		if t[i - 1] == 'A':
			ta[i] = ta[i - 1] + 1
		else:
			ta[i] = ta[i - 1]
		if t[i - 1] == 'B':
			tb[i] = tb[i - 1] + 1
		else:
			tb[i] = tb[i - 1]
	for i in range(q):
		(a, b, c, d) = map(int, input().split())
		(sl, sr) = ((sa[b] - sa[a - 1]) % 3, (sb[b] - sb[a - 1]) % 3)
		(tl, tr) = ((ta[d] - ta[c - 1]) % 3, (tb[d] - tb[c - 1]) % 3)
		sl += sr * 2
		tl += tr * 2
		sl %= 3
		tl %= 3
		if sl == tl:
			print('YES')
		else:
			print('NO')
main()


S = input().strip()
T = input().strip()
N = int(input())

def parse(s):
	cums = [0]
	for c in s:
		cums.append(cums[-1] + (1 if c == 'A' else 2))
	return cums
cumS = parse(S)
cumT = parse(T)
for _ in range(N):
	(a, b, c, d) = map(int, input().split())
	(a, b, c, d) = (a - 1, b - 1, c - 1, d - 1)
	vS = (cumS[b + 1] - cumS[a]) % 3
	vT = (cumT[d + 1] - cumT[c]) % 3
	print('YES' if vS == vT else 'NO')


import sys
from itertools import accumulate
readline = sys.stdin.readline
S = [1 if s == 'A' else 2 for s in readline().strip()]
T = [1 if s == 'A' else 2 for s in readline().strip()]
AS = [0] + list(accumulate(S))
AT = [0] + list(accumulate(T))
Q = int(readline())
Ans = [None] * Q
for qu in range(Q):
	(a, b, c, d) = map(int, readline().split())
	if (AS[b] - AS[a - 1]) % 3 != (AT[d] - AT[c - 1]) % 3:
		Ans[qu] = 'NO'
	else:
		Ans[qu] = 'YES'
print('\n'.join(map(str, Ans)))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

def main():
	s = input().strip()
	t = input().strip()
	(accs, acct) = ([0], [0])
	for i in range(len(s)):
		if s[i] == 'A':
			accs.append(accs[-1] + 1)
		else:
			accs.append(accs[-1] + 2)
	for i in range(len(t)):
		if t[i] == 'A':
			acct.append(acct[-1] + 1)
		else:
			acct.append(acct[-1] + 2)
	q = int(input())
	for _ in range(q):
		(a, b, c, d) = map(int, input().split())
		if (accs[b] - accs[a - 1]) % 3 == (acct[d] - acct[c - 1]) % 3:
			print('YES')
		else:
			print('NO')
main()


S = input()
T = input()
N = int(input())
abcd = [tuple(map(int, input().split())) for _ in range(N)]
NS = len(S)
NT = len(T)
cs0 = [0] * (NS + 1)
cs1 = [0] * (NS + 1)
ct0 = [0] * (NT + 1)
ct1 = [0] * (NT + 1)
for i in range(NS):
	cs0[i + 1] = cs0[i]
	cs1[i + 1] = cs1[i]
	if S[i] == 'A':
		cs0[i + 1] += 1
	else:
		cs1[i + 1] += 1
for i in range(NT):
	ct0[i + 1] = ct0[i]
	ct1[i + 1] = ct1[i]
	if T[i] == 'A':
		ct0[i + 1] += 1
	else:
		ct1[i + 1] += 1
for (a, b, c, d) in abcd:
	anum = cs0[b] - cs0[a - 1]
	bnum = cs1[b] - cs1[a - 1]
	num = 0
	if anum % 3 == bnum % 3 == 0:
		num = 0
	elif anum > bnum:
		num = (anum - bnum) % 3
	else:
		num = 2 * (bnum - anum) % 3
	anum2 = ct0[d] - ct0[c - 1]
	bnum2 = ct1[d] - ct1[c - 1]
	num2 = 0
	if anum2 % 3 == bnum2 % 3 == 0:
		num2 = 0
	elif anum2 > bnum2:
		num2 = (anum2 - bnum2) % 3
	else:
		num2 = 2 * (bnum2 - anum2) % 3
	if num == num2:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
S_a = [0] * (len(S) + 1)
S_b = [0] * (len(S) + 1)
T_a = [0] * (len(T) + 1)
T_b = [0] * (len(T) + 1)
for (i, s) in enumerate(S):
	if s == 'A':
		S_a[i + 1] = S_a[i] + 1
		S_b[i + 1] = S_b[i]
	else:
		S_a[i + 1] = S_a[i]
		S_b[i + 1] = S_b[i] + 1
for (i, T) in enumerate(T):
	if T == 'A':
		T_a[i + 1] = T_a[i] + 1
		T_b[i + 1] = T_b[i]
	else:
		T_a[i + 1] = T_a[i]
		T_b[i + 1] = T_b[i] + 1
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	s_a = S_a[b] - S_a[a - 1]
	s_b = S_b[b] - S_b[a - 1]
	t_a = T_a[d] - T_a[c - 1]
	t_b = T_b[d] - T_b[c - 1]
	if (t_a - t_b) % 3 == (s_a - s_b) % 3:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
S = input()
T = input()
Q = int(input())
ABCD = [list(map(int, input().split())) for _ in range(Q)]
SL = [1 if s == 'A' else 2 for s in S]
TL = [1 if t == 'A' else 2 for t in T]
AcumS = [0] + list(accumulate(SL))
AcumT = [0] + list(accumulate(TL))
for (a, b, c, d) in ABCD:
	s = AcumS[b] - AcumS[a - 1]
	t = AcumT[d] - AcumT[c - 1]
	if (s - t) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
q = int(input())
L = [[int(l) for l in input().split()] for _ in range(q)]
sumS = [0] * (len(S) + 1)
sumT = [0] * (len(T) + 1)
for i in range(len(S)):
	if S[i] == 'A':
		sumS[i + 1] += 1
	sumS[i + 1] += sumS[i]
for i in range(len(T)):
	if T[i] == 'A':
		sumT[i + 1] += 1
	sumT[i + 1] += sumT[i]
for i in range(q):
	a = sumT[L[i][3]] - sumT[L[i][2] - 1] - (sumS[L[i][1]] - sumS[L[i][0] - 1])
	b = L[i][3] - L[i][2] + 1 - (L[i][1] - L[i][0] + 1) - a
	if (a - b) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
(S, T) = (input().strip(), input().strip())
(Acc_S, Acc_T) = ([0], [0])
for s in S:
	if s == 'A':
		Acc_S.append(Acc_S[-1] + 1)
	else:
		Acc_S.append(Acc_S[-1] + 2)
for t in T:
	if t == 'A':
		Acc_T.append(Acc_T[-1] + 1)
	else:
		Acc_T.append(Acc_T[-1] + 2)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	print('YES' if (Acc_S[b] - Acc_S[a - 1]) % 3 == (Acc_T[d] - Acc_T[c - 1]) % 3 else 'NO')


s = input()
t = input()
q = int(input())
x = [1 if s[i] == 'B' else 2 for i in range(len(s))]
y = [1 if t[i] == 'B' else 2 for i in range(len(t))]
for i in range(1, len(s)):
	x[i] += x[i - 1]
for i in range(1, len(t)):
	y[i] += y[i - 1]
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	u = x[b - 1] - (x[a - 2] if 2 <= a else 0)
	v = y[d - 1] - (y[c - 2] if 2 <= c else 0)
	print('YES' if u % 3 == v % 3 else 'NO')


import sys

def solve():
	S = input()
	T = input()
	ss = [0] * (len(S) + 1)
	for i in range(len(S)):
		ss[i + 1] = ss[i]
		ss[i + 1] += 1 if S[i] == 'A' else 2
	ts = [0] * (len(T) + 1)
	for i in range(len(T)):
		ts[i + 1] = ts[i]
		ts[i + 1] += 1 if T[i] == 'A' else 2
	q = int(input())
	for qry in range(q):
		(a, b, c, d) = map(int, sys.stdin.readline().split())
		(a, c) = (a - 1, c - 1)
		sc = (ss[b] - ss[a]) % 3
		tc = (ts[d] - ts[c]) % 3
		if sc == tc:
			ans = 'YES'
		else:
			ans = 'NO'
		print(ans)

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None
solve()


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inm = lambda : list(map(int, sys.stdin.readline().split()))
inl = lambda : list(inm())
ins = lambda : sys.stdin.readline().rstrip()
S = ins()
T = ins()
conv = {'A': 1, 'B': 2}

def solve():
	cums = [0] * (len(S) + 1)
	cumt = [0] * (len(T) + 1)
	for (i, x) in enumerate(S):
		c = conv[x]
		cums[i + 1] = (cums[i] + c) % 3
	for (i, x) in enumerate(T):
		c = conv[x]
		cumt[i + 1] = (cumt[i] + c) % 3
	q = ini()
	for i in range(q):
		(a, b, c, d) = inm()
		if (cums[b] - cums[a - 1]) % 3 == (cumt[d] - cumt[c - 1]) % 3:
			print('YES')
		else:
			print('NO')
solve()


s = input()
t = input()
n = int(input())
a = [[0 for i in range(4)] for j in range(n)]
for i in range(n):
	a[i] = [int(j) - 1 for j in input().split()]

def henkan(inp, n):
	o = [0] * n
	for i in range(n):
		if inp[i] == 'A':
			o[i] = 1
		else:
			o[i] = 2
	return o

def ruiseki(a, n):
	s = [0] * n
	s[0] = a[0]
	for i in range(1, n):
		s[i] = s[i - 1] + a[i]
	return s

def partSum(s, l, r):
	if l == 0:
		return s[r]
	return s[r] - s[l - 1]
s_i = henkan(s, len(s))
t_i = henkan(t, len(t))
sum_s = ruiseki(s_i, len(s_i))
sum_t = ruiseki(t_i, len(t_i))
for i in range(n):
	x = partSum(sum_s, a[i][0], a[i][1])
	y = partSum(sum_t, a[i][2], a[i][3])
	if x % 3 == y % 3:
		print('YES')
	else:
		print('NO')


(s, t, q) = (list(input()), list(input()), int(input()))
(ssum, tsum) = ([0], [0])
for i in range(len(s)):
	if s[i] == 'A':
		ssum.append(ssum[-1] + 1)
	else:
		ssum.append(ssum[-1] + 2)
for i in range(len(t)):
	if t[i] == 'A':
		tsum.append(tsum[-1] + 1)
	else:
		tsum.append(tsum[-1] + 2)
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	sa = ssum[b] - ssum[a - 1] - (tsum[d] - tsum[c - 1])
	if abs(sa) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
S = list(input())[:-1]
T = list(input())[:-1]
css = [0] * (len(S) + 1)
cst = [0] * (len(T) + 1)
for i in range(len(S)):
	css[i + 1] = css[i] + (S[i] == 'A') + (S[i] == 'B') * 2
for i in range(len(T)):
	cst[i + 1] = cst[i] + (T[i] == 'A') + (T[i] == 'B') * 2
for _ in range(int(input())):
	(a, b, u, v) = map(int, input().split())
	if (css[b] - css[a - 1]) % 3 == (cst[v] - cst[u - 1]) % 3:
		print('YES')
	else:
		print('NO')


def solve(s, t, q):
	cnt_s = [0] * (len(s) + 1)
	cnt_t = [0] * (len(t) + 1)
	r = 0
	for i in range(len(s)):
		cnt_s[i] = r
		if s[i] == 'A':
			r += 1
	cnt_s[-1] = r
	r = 0
	for i in range(len(t)):
		cnt_t[i] = r
		if t[i] == 'A':
			r += 1
	cnt_t[-1] = r
	ans = []
	for _ in range(q):
		(a, b, c, d) = input().split()
		a = int(a) - 1
		b = int(b)
		c = int(c) - 1
		d = int(d)
		cs = cnt_s[b] - cnt_s[a]
		ms = (2 * (b - a) - cs) % 3
		ct = cnt_t[d] - cnt_t[c]
		mt = (2 * (d - c) - ct) % 3
		ans.append(ms == mt)
	for r in ans:
		print('YES' if r else 'NO')

def main():
	s = input()
	t = input()
	q = input()
	q = int(q)
	solve(s, t, q)
main()


import sys

def input():
	return sys.stdin.readline().rstrip()

def yes():
	print('YES')

def no():
	print('NO')

def solve():
	S = input()
	T = input()
	lenS = len(S)
	lenT = len(T)
	Q = int(input())
	Query = [tuple(map(int, input().split())) for i in range(Q)]
	S_cnt = [0] * (lenS + 1)
	T_cnt = [0] * (lenT + 1)
	for i in range(lenS):
		if S[i] == 'A':
			S_cnt[i + 1] += 1
		else:
			S_cnt[i + 1] -= 1
	for i in range(lenS):
		S_cnt[i + 1] += S_cnt[i]
	for i in range(lenT):
		if T[i] == 'A':
			T_cnt[i + 1] += 1
		else:
			T_cnt[i + 1] -= 1
	for i in range(lenT):
		T_cnt[i + 1] += T_cnt[i]
	for (a, b, c, d) in Query:
		modS = (S_cnt[b] - S_cnt[a - 1]) % 3
		modT = (T_cnt[d] - T_cnt[c - 1]) % 3
		if modS == modT:
			yes()
		else:
			no()
	return
solve()


S = input()
T = input()
q = int(input())
table = []
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	(a, b, c, d) = (a - 1, b - 1, c - 1, d - 1)
	table.append((a, b, c, d))
N = len(S)
M = len(T)
A = [[0] * (N + 1) for i in range(2)]
B = [[0] * (N + 1) for i in range(2)]
for i in range(1, N + 1):
	if S[i - 1] == 'A':
		A[0][i] += A[0][i - 1] + 1
		A[1][i] += A[1][i - 1]
	else:
		A[0][i] += A[0][i - 1]
		A[1][i] += A[1][i - 1] + 1
for i in range(1, M + 1):
	if T[i - 1] == 'A':
		B[0][i] += B[0][i - 1] + 1
		B[1][i] += B[1][i - 1]
	else:
		B[0][i] += B[0][i - 1]
		B[1][i] += B[1][i - 1] + 1
for i in range(q):
	(a, b, c, d) = table[i]
	x = A[0][b + 1] - A[0][a]
	y = A[1][b + 1] - A[1][a]
	z = B[0][d + 1] - B[0][c]
	w = B[1][d + 1] - B[1][c]
	if (x + 2 * y) % 3 == (z + 2 * w) % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
cumsa = [0]
cumsb = [0]
for c in S:
	cumsa.append(cumsa[-1] + int(c == 'A'))
	cumsb.append(cumsb[-1] + int(c == 'B'))
cumta = [0]
cumtb = [0]
for c in T:
	cumta.append(cumta[-1] + int(c == 'A'))
	cumtb.append(cumtb[-1] + int(c == 'B'))
Q = int(input())
ans = []
for i in range(Q):
	(a, b, c, d) = map(int, input().split())
	sa = cumsa[b] - cumsa[a - 1]
	sb = cumsb[b] - cumsb[a - 1]
	ta = cumta[d] - cumta[c - 1]
	tb = cumtb[d] - cumtb[c - 1]
	ans.append('YES' if (sa - sb) % 3 == (ta - tb) % 3 else 'NO')
print('\n'.join(ans))


from itertools import accumulate
import sys
S = input()
T = input()
ns = len(S)
nt = len(T)
SA = [0] * (ns + 1)
SB = [0] * (ns + 1)
TA = [0] * (nt + 1)
TB = [0] * (nt + 1)
for (i, s) in enumerate(S, 1):
	if s == 'A':
		SA[i] = 1
	else:
		SB[i] = 1
for (i, t) in enumerate(T, 1):
	if t == 'A':
		TA[i] = 1
	else:
		TB[i] = 1
SA = list(accumulate(SA))
SB = list(accumulate(SB))
TA = list(accumulate(TA))
TB = list(accumulate(TB))
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	sa = SA[b] - SA[a - 1]
	sb = SB[b] - SB[a - 1]
	ta = TA[d] - TA[c - 1]
	tb = TB[d] - TB[c - 1]
	sb += 2 * sa
	tb += 2 * ta
	if abs(sb - tb) % 3 == 0:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
S = input()
T = input()
q = int(input())
abcds = [tuple(map(int, input().split())) for _ in range(q)]
S_csum = list(map(lambda x: x % 3, accumulate(map(lambda c: 1 if c == 'A' else -1, S), initial=0)))
T_csum = list(map(lambda x: x % 3, accumulate(map(lambda c: 1 if c == 'A' else -1, T), initial=0)))
for (a, b, c, d) in abcds:
	if (S_csum[b] - S_csum[a - 1]) % 3 == (T_csum[d] - T_csum[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import sys
read = sys.stdin.read
readline = sys.stdin.readline

def main():
	S = readline().rstrip()
	T = readline().rstrip()
	Q = int(readline())
	l = len(S)
	m = len(T)
	S_acc = [0] * (l + 1)
	T_acc = [0] * (m + 1)
	for i in range(l):
		ch = 1 if S[i] == 'A' else 2
		S_acc[i + 1] = S_acc[i] + ch
	for i in range(m):
		ch = 1 if T[i] == 'A' else 2
		T_acc[i + 1] = T_acc[i] + ch
	for i in range(Q):
		(a, b, c, d) = list(map(int, readline().split()))
		first = S_acc[b] - S_acc[a - 1]
		second = T_acc[d] - T_acc[c - 1]
		if (first - second) % 3 == 0:
			print('YES')
		else:
			print('NO')

def __starting_point():
	INF = float('INF')
	MOD = 10 ** 9 + 7
	sys.setrecursionlimit(10 ** 5)
	main()
__starting_point()


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float('inf')

def main():
	S = input()
	T = input()
	(s_sum, t_sum) = ([0] * (len(S) + 1), [0] * (len(T) + 1))
	for i in range(len(S)):
		s_sum[i + 1] = s_sum[i] + (1 if S[i] == 'A' else 2)
	for i in range(len(T)):
		t_sum[i + 1] = t_sum[i] + (1 if T[i] == 'A' else 2)
	for _ in range(int(input())):
		(a, b, c, d) = map(lambda x: int(x) - 1, input().split())
		s = s_sum[b + 1] - s_sum[a]
		t = t_sum[d + 1] - t_sum[c]
		print('YES' if s % 3 == t % 3 else 'NO')
main()


S = input().rstrip()
T = input().rstrip()
AS = [0]
AT = [0]
for s in S:
	if s == 'A':
		AS.append(AS[-1] + 1)
	else:
		AS.append(AS[-1] + 2)
for s in T:
	if s == 'A':
		AT.append(AT[-1] + 1)
	else:
		AT.append(AT[-1] + 2)
Q = int(input())
for _ in range(Q):
	(a, b, c, d) = map(int, input().split())
	if (AS[b] - AS[a - 1]) % 3 == (AT[d] - AT[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def acc(li, n):
	res = [0] * (n + 1)
	for i in range(n):
		if li[i] == 'A':
			res[i + 1] = 1
		elif li[i] == 'B':
			res[i + 1] = 2
	return list(accumulate(res))

def restore(x, y, li):
	return (li[y] - li[x - 1]) % 3
S = input()
T = input()
N = len(S)
M = len(T)
acc_S = acc(S, N)
acc_T = acc(T, M)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	v_S = restore(a, b, acc_S)
	v_T = restore(c, d, acc_T)
	print('YES') if v_S == v_T else print('NO')


from itertools import accumulate
convert = {'A': 1, 'B': 2}
S = tuple((convert[x] for x in input()))
T = tuple((convert[x] for x in input()))
acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))
ans = []
Q = int(input())
for _ in range(Q):
	(sl, sr, tl, tr) = map(int, input().split())
	diff = acc_t[tr] - acc_t[tl - 1] - (acc_s[sr] - acc_s[sl - 1])
	ans.append('YES' if diff % 3 == 0 else 'NO')
print(*ans, sep='\n')


def inpl():
	return [int(i) for i in input().split()]
S = input()
T = input()
typeS = [0 for _ in range(1 + len(S))]
typeT = [0 for _ in range(1 + len(T))]
typeS[0] = typeT[0] = 0
for i in range(len(S)):
	ctr = 2
	if S[i] == 'A':
		ctr = 1
	typeS[i + 1] = (typeS[i] + ctr) % 3
for i in range(len(T)):
	ctr = 2
	if T[i] == 'A':
		ctr = 1
	typeT[i + 1] = (typeT[i] + ctr) % 3
Q = int(input())
for _ in range(Q):
	(a, b, c, d) = inpl()
	if (typeS[b] - typeS[a - 1]) % 3 == (typeT[d] - typeT[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
import sys
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = tuple(accumulate([1 if x == 'A' else 2 for x in input().rstrip()]))
T = tuple(accumulate([1 if x == 'A' else 2 for x in input().rstrip()]))
input()
for line in readlines():
	(a, b, c, d) = [int(x) - 1 for x in line.split()]
	s = S[b] - S[a - 1] if a else S[b]
	t = T[d] - T[c - 1] if c else T[d]
	print('YES' if s % 3 == t % 3 else 'NO')


def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getArray(intn):
	return [int(input()) for i in range(intn)]

def input():
	return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):
	return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):
	return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):
	ns = []
	while len(ns) < rantime:
		n = random.randint(ran1, ran2)
		if not n in ns:
			ns.append(n)
	return sorted(ns)

def rand_query(ran1, ran2, rantime):
	r_query = []
	while len(r_query) < rantime:
		n_q = rand_ints_nodup(ran1, ran2, 2)
		if not n_q in r_query:
			r_query.append(n_q)
	return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
S = input()
T = input()
Q = getN()
que = [getList() for i in range(Q)]
imos_s = [0]
for i in range(len(S)):
	if S[i] == 'A':
		imos_s.append(imos_s[i] + 1)
	else:
		imos_s.append(imos_s[i] + 2)
imos_t = [0]
for i in range(len(T)):
	if T[i] == 'A':
		imos_t.append(imos_t[i] + 1)
	else:
		imos_t.append(imos_t[i] + 2)
for i in range(Q):
	(a, b, c, d) = que[i]
	opt_1 = (imos_s[b] - imos_s[a - 1]) % 3
	opt_2 = (imos_t[d] - imos_t[c - 1]) % 3
	if opt_1 == opt_2:
		print('YES')
	else:
		print('NO')


S = list(input())
T = list(input())
q = int(input())
l = []
for i in range(q):
	l.append(list(map(int, input().split(' '))))
sta = [0 for i in range(len(S))]
stb = [0 for i in range(len(S))]
tta = [0 for i in range(len(T))]
ttb = [0 for i in range(len(T))]
if S[0] == 'A':
	sta[0] = 1
else:
	stb[0] = 1
if T[0] == 'A':
	tta[0] = 1
else:
	ttb[0] = 1
for i in range(1, len(S)):
	if S[i] == 'A':
		sta[i] = sta[i - 1] + 1
		stb[i] = stb[i - 1]
	else:
		sta[i] = sta[i - 1]
		stb[i] = stb[i - 1] + 1
for i in range(1, len(T)):
	if T[i] == 'A':
		tta[i] = tta[i - 1] + 1
		ttb[i] = ttb[i - 1]
	else:
		tta[i] = tta[i - 1]
		ttb[i] = ttb[i - 1] + 1

def get(l, a, b):
	if a == 0:
		return l[b]
	else:
		return l[b] - l[a - 1]
for (a, b, c, d) in l:
	sa = get(sta, a - 1, b - 1)
	sb = get(stb, a - 1, b - 1)
	ta = get(tta, c - 1, d - 1)
	tb = get(ttb, c - 1, d - 1)
	if (sa + sb * 2) % 3 == (ta + tb * 2) % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
n = len(s)
m = len(t)
sl = [0]
for i in s:
	sl.append(sl[-1])
	if i == 'A':
		sl[-1] += 1
	else:
		sl[-1] += 2
	sl[-1] %= 3
tl = [0]
for i in t:
	tl.append(tl[-1])
	if i == 'A':
		tl[-1] += 1
	else:
		tl[-1] += 2
	tl[-1] %= 3
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	a -= 1
	c -= 1
	ss = sl[b] - sl[a]
	tt = tl[d] - tl[c]
	if ss % 3 == tt % 3:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def main():
	S = input()
	T = input()
	scnt = [0] * (len(S) + 1)
	for i in range(len(S)):
		scnt[i + 1] = scnt[i] + (1 if S[i] == 'A' else 2)
	tcnt = [0] * (len(T) + 1)
	for i in range(len(T)):
		tcnt[i + 1] = tcnt[i] + (1 if T[i] == 'A' else 2)
	q = int(input())
	for _ in range(q):
		(a, b, c, d) = map(int, input().split())
		sn = scnt[b] - scnt[a - 1]
		tn = tcnt[d] - tcnt[c - 1]
		if sn % 3 == tn % 3:
			print('YES')
		else:
			print('NO')
main()


import sys
input = sys.stdin.readline
from itertools import accumulate
s = input()[:-1]
t = input()[:-1]
d = {'A': 1, 'B': 2}
ds = [0] + list(accumulate([d[x] for x in s]))
dt = [0] + list(accumulate([d[x] for x in t]))
ans = []
append = ans.append
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if (ds[b] - ds[a - 1]) % 3 == (dt[d] - dt[c - 1]) % 3:
		append('YES')
	else:
		append('NO')
print('\n'.join(ans))


s = input()
t = input()
q = int(input())
C = [list(map(int, input().split())) for i in range(q)]
S = [0]
T = [0]
for i in range(len(s)):
	if s[i] == 'A':
		S.append(1)
	else:
		S.append(2)
for i in range(1, len(S)):
	S[i] = (S[i - 1] + S[i]) % 3
for i in range(len(t)):
	if t[i] == 'A':
		T.append(1)
	else:
		T.append(2)
for i in range(1, len(T)):
	T[i] = (T[i - 1] + T[i]) % 3
for i in range(q):
	ss = (S[C[i][1]] - S[C[i][0] - 1]) % 3
	tt = (T[C[i][3]] - T[C[i][2] - 1]) % 3
	print('YES' if ss == tt else 'NO')


import sys
input = sys.stdin.readline
S = input()
T = input()
q = int(input())
abcd = [list(map(int, input().split())) for i in range(q)]

class SegmentTree:

	def __init__(self, data, op, default):
		N = len(data)
		self.N = N
		self.op = op
		self.default = default
		self.l = 2 ** (N - 1).bit_length()
		self.data = [default] * self.l + data + [default] * (self.l - N)
		for i in range(self.l - 1, 0, -1):
			self.data[i] = op(self.data[2 * i], self.data[2 * i + 1])

	def get_data(self, i=None):
		if i is None:
			return self.data[self.l:self.l + self.N]
		else:
			return self.data[self.l + i]

	def set(self, i, val):
		i += self.l
		self.data[i] = val
		i = i // 2
		while i > 0:
			self.data[i] = self.op(self.data[2 * i], self.data[2 * i + 1])
			i = i // 2

	def get(self, i, j):
		i += self.l
		j += self.l
		s = self.default
		while j - i > 0:
			if i & 1:
				s = self.op(s, self.data[i])
				i += 1
			if j & 1:
				s = self.op(s, self.data[j - 1])
				j -= 1
			(i, j) = (i // 2, j // 2)
		return s
convert = lambda x: 1 if x == 'A' else 2
nS = list(map(convert, S))
nT = list(map(convert, T))
segS = SegmentTree(nS, lambda x, y: x + y, 0)
segT = SegmentTree(nT, lambda x, y: x + y, 0)
for (a, b, c, d) in abcd:
	rs = segS.get(a - 1, b)
	rt = segT.get(c - 1, d)
	if (rs - rt) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
rui_s = [0]
rui_t = [0]
for s in S:
	if s == 'A':
		rui_s.append((rui_s[-1] + 1) % 3)
	else:
		rui_s.append((rui_s[-1] + 2) % 3)
for t in T:
	if t == 'A':
		rui_t.append((rui_t[-1] + 1) % 3)
	else:
		rui_t.append((rui_t[-1] + 2) % 3)
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if (rui_s[b] - rui_s[a - 1]) % 3 == (rui_t[d] - rui_t[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
cs = [0]
for i in s:
	if i == 'A':
		cs.append((cs[-1] + 1) % 3)
	else:
		cs.append((cs[-1] + 2) % 3)
ct = [0]
for i in t:
	if i == 'A':
		ct.append((ct[-1] + 1) % 3)
	else:
		ct.append((ct[-1] + 2) % 3)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if (cs[b] - cs[a - 1]) % 3 == (ct[d] - ct[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
q = int(input())
ans = ['YES'] * q
scnt = [[0] * (len(s) + 1) for _ in range(2)]
tcnt = [[0] * (len(t) + 1) for _ in range(2)]
for (i, S) in enumerate(s):
	scnt[0][i + 1] = scnt[0][i]
	scnt[1][i + 1] = scnt[1][i]
	scnt[ord(S) - ord('A')][i + 1] += 1
for (i, T) in enumerate(t):
	tcnt[0][i + 1] = tcnt[0][i]
	tcnt[1][i + 1] = tcnt[1][i]
	tcnt[ord(T) - ord('A')][i + 1] += 1
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	a -= 1
	c -= 1
	A = scnt[0][b] - scnt[0][a] - tcnt[0][d] + tcnt[0][c]
	B = scnt[1][b] - scnt[1][a] - tcnt[1][d] + tcnt[1][c]
	if (A - B) % 3 != 0:
		ans[i] = 'NO'
print('\n'.join(ans))


s = input()
t = input()

def cumsum_list(inlist):
	l = len(inlist)
	out_cumsum_list = [None for i in range(l + 1)]
	out_cumsum_list[0] = (0, 0)
	for i in range(l):
		if inlist[i] == 'A':
			out_cumsum_list[i + 1] = (out_cumsum_list[i][0] + 1, out_cumsum_list[i][1])
		else:
			out_cumsum_list[i + 1] = (out_cumsum_list[i][0], out_cumsum_list[i][1] + 1)
	return out_cumsum_list
cumsum_list_s = cumsum_list(s)
cumsum_list_t = cumsum_list(t)
n = int(input())
for i in range(n):
	(a, b, c, d) = [int(v) for v in input().split()]
	sa = cumsum_list_s[b][0] - cumsum_list_s[a - 1][0]
	sb = cumsum_list_s[b][1] - cumsum_list_s[a - 1][1]
	ta = cumsum_list_t[d][0] - cumsum_list_t[c - 1][0]
	tb = cumsum_list_t[d][1] - cumsum_list_t[c - 1][1]
	(total_s, total_t) = (sa + 2 * sb, ta + 2 * tb)
	if total_s % 3 == total_t % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
q = int(input())
SA = [0]
SB = [0]
TA = [0]
TB = [0]
sa = 0
sb = 0
ta = 0
tb = 0
for i in range(len(S)):
	if S[i] == 'A':
		sa += 1
	elif S[i] == 'B':
		sb += 1
	SA.append(sa)
	SB.append(sb)
for i in range(len(T)):
	if T[i] == 'A':
		ta += 1
	elif T[i] == 'B':
		tb += 1
	TA.append(ta)
	TB.append(tb)
for i in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	sa_num = SA[b] - SA[a - 1]
	sb_num = SB[b] - SB[a - 1]
	ta_num = TA[d] - TA[c - 1]
	tb_num = TB[d] - TB[c - 1]
	if (sa_num + 2 * sb_num) % 3 == (ta_num + 2 * tb_num) % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
Q = int(input())
nS = [[0, 0]]
nT = [[0, 0]]
for (i, c) in enumerate(S):
	nS.append([abs(ord(c) - ord('A')), abs(ord(c) - ord('B'))])
	nS[i + 1][0] += nS[i][0]
	nS[i + 1][1] += nS[i][1]
for (i, c) in enumerate(T):
	nT.append([abs(ord(c) - ord('A')), abs(ord(c) - ord('B'))])
	nT[i + 1][0] += nT[i][0]
	nT[i + 1][1] += nT[i][1]
for qawsedrftgyhujikolp in range(Q):
	(a, b, c, d) = map(int, input().split())
	if (nS[b][0] - nS[a - 1][0] + 2 * nS[b][1] - 2 * nS[a - 1][1]) % 3 == (nT[d][0] - nT[c - 1][0] + 2 * nT[d][1] - 2 * nT[c - 1][1]) % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
d = {'A': 1, 'B': -1}

def make(s):
	ss = [0]
	for i in s:
		if ss[-1] == 0:
			ss.append(d[i])
		elif ss[-1] == d[i]:
			ss.append(ss[-1] * -1)
		else:
			ss.append(0)
	return ss
sl = make(s)
tl = make(t)

def convert(a, b):
	if a == 0:
		return b
	if a == 1:
		c = b - a
		if c == -2:
			c = 1
		return c
	if a == -1:
		c = b - a
		if c == 2:
			c = -1
		return c
q = int(input())
ans = []
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	sleft = sl[a - 1]
	sright = sl[b]
	tleft = tl[c - 1]
	tright = tl[d]
	if convert(sleft, sright) == convert(tleft, tright):
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
import itertools
convert = {'A': 1, 'B': 2}
S = [convert[x] for x in input().rstrip()]
T = [convert[x] for x in input().rstrip()]
Scum = [0] + list(itertools.accumulate(S))
Tcum = [0] + list(itertools.accumulate(T))
Q = int(input())
answer = []
for _ in range(Q):
	(a, b, c, d) = map(int, input().split())
	x = Scum[b] - Scum[a - 1]
	y = Tcum[d] - Tcum[c - 1]
	answer.append('YES' if x % 3 == y % 3 else 'NO')
print('\n'.join(answer))


import sys
input = sys.stdin.readline
s = list(input())
t = list(input())
snum = [(0, 0)]
for i in range(len(s)):
	if s[i] == 'A':
		snum.append((snum[-1][0] + 1, snum[-1][1]))
	else:
		snum.append((snum[-1][0], snum[-1][1] + 1))
tnum = [(0, 0)]
for i in range(len(t)):
	if t[i] == 'A':
		tnum.append((tnum[-1][0] + 1, tnum[-1][1]))
	else:
		tnum.append((tnum[-1][0], tnum[-1][1] + 1))
q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	sa = snum[b][0] - snum[a - 1][0]
	sb = snum[b][1] - snum[a - 1][1]
	ta = tnum[d][0] - tnum[c - 1][0]
	tb = tnum[d][1] - tnum[c - 1][1]
	b1 = sb + sa * 2
	b1 += max(tb - b1, 0) // 3 * 3 + 3
	a1 = (b1 - tb) * 2
	if abs(a1 - ta) % 3 == 0:
		print('YES')
		continue
	a2 = sa + sb * 2
	a2 += max(ta - a2, 0) // 3 * 3 + 3
	b2 = (a2 - ta) * 2
	if abs(b2 - tb) % 3 == 0:
		print('YES')
		continue
	print('NO')


S = input()
T = input()
q = int(input())
S_rel_idx = [0]
T_rel_idx = [0]
for s in S:
	if s == 'A':
		S_rel_idx.append((S_rel_idx[-1] + 1) % 3)
	else:
		S_rel_idx.append((S_rel_idx[-1] - 1) % 3)
for t in T:
	if t == 'A':
		T_rel_idx.append((T_rel_idx[-1] + 1) % 3)
	else:
		T_rel_idx.append((T_rel_idx[-1] - 1) % 3)
for _ in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	if (S_rel_idx[b] - S_rel_idx[a - 1]) % 3 == (T_rel_idx[d] - T_rel_idx[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
S = input()
T = input()
SAdata = [int(S[i] == 'A') for i in range(len(S))]
SBdata = [int(S[i] == 'B') for i in range(len(S))]
for i in range(1, len(S)):
	SAdata[i] += SAdata[i - 1]
for i in range(1, len(S)):
	SBdata[i] += SBdata[i - 1]
SAdata.append(0)
SBdata.append(0)
TAdata = [int(T[i] == 'A') for i in range(len(T))]
TBdata = [int(T[i] == 'B') for i in range(len(T))]
for i in range(1, len(T)):
	TAdata[i] += TAdata[i - 1]
for i in range(1, len(T)):
	TBdata[i] += TBdata[i - 1]
TAdata.append(0)
TBdata.append(0)
q = int(input())
for i in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	SA = SAdata[b - 1] - SAdata[a - 2]
	SB = SBdata[b - 1] - SBdata[a - 2]
	TA = TAdata[d - 1] - TAdata[c - 2]
	TB = TBdata[d - 1] - TBdata[c - 2]
	if (SA - SB) % 3 == (TA - TB) % 3:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def solve():
	(S, T) = (input(), input())
	q = int(input())
	(ls, lt) = (len(S), len(T))
	(acs, act) = ([0] * (ls + 1), [0] * (lt + 1))
	for i in range(1, ls + 1):
		acs[i] = acs[i - 1] + (S[i - 1] == 'A')
	for i in range(1, lt + 1):
		act[i] = act[i - 1] + (T[i - 1] == 'A')
	for _ in range(q):
		(a, b, c, d) = list(map(int, input().split()))
		print('YES' if (acs[b] - acs[a - 1] + b - a + 1) % 3 == (act[d] - act[c - 1] + d - c + 1) % 3 else 'NO')

def __starting_point():
	solve()
__starting_point()


S = [0] + [1 if a == 'A' else 2 for a in input()]
T = [0] + [1 if a == 'A' else 2 for a in input()]
for i in range(1, len(S)):
	S[i] += S[i - 1]
for i in range(1, len(T)):
	T[i] += T[i - 1]
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if (S[b] - S[a - 1] - T[d] + T[c - 1]) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
T = input()

def sign(s):
	if len(s) == 1:
		return s
	elif s == 'AA':
		return 'B'
	elif s in ['AB', 'BA']:
		return ''
	elif s == 'BB':
		return 'A'

def diff(a, b):
	if b == '':
		return a
	elif b == a:
		return ''
	elif a == '':
		if b == 'A':
			return 'B'
		elif b == 'B':
			return 'A'
	else:
		return b
a = ''
Sn = ['']
for s in S:
	a = sign(a + s)
	Sn.append(a)
a = ''
Tn = ['']
for t in T:
	a = sign(a + t)
	Tn.append(a)
q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	if diff(Sn[b], Sn[a - 1]) == diff(Tn[d], Tn[c - 1]):
		print('YES')
	else:
		print('NO')


s = input()
t = input()
q = int(input())
xa = [0] * len(s) + [0]
xb = [0] * len(s) + [0]
ya = [0] * len(t) + [0]
yb = [0] * len(t) + [0]
for i in range(len(s)):
	if s[i] == 'A':
		xa[i + 1] = xa[i] + 1
		xb[i + 1] = xb[i]
	else:
		xa[i + 1] = xa[i]
		xb[i + 1] = xb[i] + 1
for i in range(len(t)):
	if t[i] == 'A':
		ya[i + 1] = ya[i] + 1
		yb[i + 1] = yb[i]
	else:
		ya[i + 1] = ya[i]
		yb[i + 1] = yb[i] + 1
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	sa = (xa[b] - xa[a - 1]) % 3
	sb = (xb[b] - xb[a - 1]) % 3
	ta = (ya[d] - ya[c - 1]) % 3
	tb = (yb[d] - yb[c - 1]) % 3
	if [(sa - 1) % 3, (sb + 2) % 3] == [ta, tb] or [(sa + 2) % 3, (sb - 1) % 3] == [ta, tb] or [sa, sb] == [ta, tb] or ([(sa - 2) % 3, (sb + 4) % 3] == [ta, tb]) or ([(sa + 4) % 3, (sb - 2) % 3] == [ta, tb]):
		print('YES')
	else:
		print('NO')


s = list(input())
t = list(input())
s = [0] + [1 if si == 'A' else 2 for si in s]
t = [0] + [1 if ti == 'A' else 2 for ti in t]
import numpy as np
s = np.array(s)
t = np.array(t)
s = np.cumsum(s)
t = np.cumsum(t)
q = int(input())
for _ in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	a -= 1
	c -= 1
	test = s[b] - s[a] - t[d] + t[c]
	test %= 3
	if not test:
		print('YES')
	else:
		print('NO')


(S, T) = (input(), input())
q = int(input())
(ls, lt) = (len(S), len(T))
(acs, act) = ([0] * (ls + 1), [0] * (lt + 1))
for i in range(1, ls + 1):
	acs[i] = acs[i - 1] + (S[i - 1] == 'A')
for i in range(1, lt + 1):
	act[i] = act[i - 1] + (T[i - 1] == 'A')
for _ in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	sa = acs[b] - acs[a - 1]
	sb = b - a + 1 - sa
	ta = act[d] - act[c - 1]
	tb = d - c + 1 - ta
	print('YES' if (2 * sa + sb) % 3 == (2 * ta + tb) % 3 else 'NO')


s = input()
t = input()
(S, T) = ([0] * (len(s) + 1), [0] * (len(t) + 1))
for i in range(len(s)):
	if s[i] == 'A':
		S[i + 1] = S[i] + 1
	else:
		S[i + 1] = S[i] - 1
for i in range(len(t)):
	if t[i] == 'A':
		T[i + 1] = T[i] + 1
	else:
		T[i + 1] = T[i] - 1
q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	ss = S[b] - S[a - 1]
	tt = T[d] - T[c - 1]
	if (ss - tt) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def make_acc(U):
	res = [0]
	for (i, u) in enumerate(U):
		res.append((res[-1] + (1 if u == 'A' else 2)) % 3)
	return res

def judge(acc, p, q):
	return (acc[q] - acc[p - 1]) % 3
S = input()
T = input()
(S_acc, T_acc) = (make_acc(S), make_acc(T))
Q = int(input())
for _ in range(Q):
	(a, b, c, d) = list(map(int, input().split()))
	print('YES' if judge(S_acc, a, b) == judge(T_acc, c, d) else 'NO')


S = input()
T = input()
q = int(input())
s = [0]
t = [0]
v = 0
for c in S:
	v = (v + (ord(c) - ord('A') + 1)) % 3
	s.append(v)
v = 0
for c in T:
	v = (v + (ord(c) - ord('A') + 1)) % 3
	t.append(v)
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	x = (3 + s[b] - s[a - 1]) % 3
	y = (3 + t[d] - t[c - 1]) % 3
	if x == y:
		print('YES')
	else:
		print('NO')


import itertools
S = list(itertools.accumulate([0] + [1 if s == 'A' else 0 for s in input()]))
T = list(itertools.accumulate([0] + [1 if t == 'A' else 0 for t in input()]))
Q = int(input())
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
for (a, b, c, d) in ABCD:
	x = b - a + 1 + (S[b] - S[a - 1])
	y = d - c + 1 + (T[d] - T[c - 1])
	print('NO') if (x - y) % 3 else print('YES')


from random import *

def readln():
	_res = list(map(int, str(input()).split(' ')))
	return _res

def calc(s):
	res = [0 for ch in s]
	prev = 0
	for i in range(0, len(s)):
		if s[i] == 'A':
			res[i] = (prev - 1) % 3
		elif s[i] == 'B':
			res[i] = (prev + 1) % 3
		prev = res[i]
	return res

def sum(l, r, s):
	l = l - 1
	r = r - 1
	if l > 0:
		res = s[r] - s[l - 1]
	else:
		res = s[r]
	return (res + 30000) % 3
s = input()
t = input()
ss = calc(s)
st = calc(t)
q = readln()[0]
for i in range(0, q):
	(a, b, c, d) = readln()
	x = sum(a, b, ss)
	y = sum(c, d, st)
	if x == y:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
q = int(input())
n = len(s)
pre = [0] * (n + 1)
for i in range(n):
	if s[i] == 'A':
		pre[i] = pre[i - 1] + 1
	else:
		pre[i] = pre[i - 1]
m = len(t)
p = [0] * (m + 1)
for i in range(m):
	if t[i] == 'A':
		p[i] = p[i - 1] + 1
	else:
		p[i] = p[i - 1]
for _ in range(q):
	(a, b, c, d) = map(lambda x: int(x) - 1, input().split())
	aa = pre[b] - pre[a - 1]
	co = b - a + 1 - aa
	co += aa * 2
	bb = p[d] - p[c - 1]
	do = d - c + 1 - bb
	do += bb * 2
	co %= 3
	do %= 3
	if co == do:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
(*S,) = [1 if x == 'A' else 2 for x in input()]
(*T,) = [1 if x == 'A' else 2 for x in input()]
acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))
Q = int(input())
for _ in range(Q):
	(sl, sr, tl, tr) = list(map(int, input().split()))
	sl -= 1
	tl -= 1
	diff = acc_t[tr] - acc_t[tl] - (acc_s[sr] - acc_s[sl])
	print('YES' if diff % 3 == 0 else 'NO')


import sys
input = sys.stdin.readline
S = input()[:-1]
T = input()[:-1]
(acc0, acc1) = ([0] * (len(S) + 1), [0] * (len(S) + 1))
for i in range(len(S)):
	acc0[i + 1] = acc0[i] + (1 if S[i] == 'A' else 0)
	acc1[i + 1] = acc1[i] + (1 if S[i] == 'B' else 0)
(acc2, acc3) = ([0] * (len(T) + 1), [0] * (len(T) + 1))
for i in range(len(T)):
	acc2[i + 1] = acc2[i] + (1 if T[i] == 'A' else 0)
	acc3[i + 1] = acc3[i] + (1 if T[i] == 'B' else 0)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	A_diff = acc0[b] - acc0[a - 1] - (acc2[d] - acc2[c - 1])
	B_diff = acc1[b] - acc1[a - 1] - (acc3[d] - acc3[c - 1])
	if A_diff % 3 == B_diff % 3:
		print('YES')
	else:
		print('NO')


S = list(input())
T = list(input())
import sys
input = sys.stdin.readline
S_n = [0] * (len(S) + 1)
for i in range(1, len(S) + 1):
	if S[i - 1] == 'A':
		S_n[i] = S_n[i - 1] + 1
	else:
		S_n[i] = S_n[i - 1] + 2
T_n = [0] * (len(T) + 1)
for i in range(1, len(T) + 1):
	if T[i - 1] == 'A':
		T_n[i] = T_n[i - 1] + 1
	else:
		T_n[i] = T_n[i - 1] + 2
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	S_A = S_n[b] - S_n[a - 1]
	T_A = T_n[d] - T_n[c - 1]
	delta = abs(S_A - T_A)
	if delta % 3 == 0:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
q = int(input())
acums = [[0, 0] for _ in range(len(s) + 1)]
for i in range(1, len(s) + 1):
	if s[i - 1] == 'A':
		acums[i][0] = acums[i - 1][0] + 1
		acums[i][1] = acums[i - 1][1]
	else:
		acums[i][0] = acums[i - 1][0]
		acums[i][1] = acums[i - 1][1] + 1
acumt = [[0, 0] for _ in range(len(t) + 1)]
for i in range(1, len(t) + 1):
	if t[i - 1] == 'A':
		acumt[i][0] = acumt[i - 1][0] + 1
		acumt[i][1] = acumt[i - 1][1]
	else:
		acumt[i][0] = acumt[i - 1][0]
		acumt[i][1] = acumt[i - 1][1] + 1
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	cnt1 = (acums[b][0] - acums[a - 1][0]) * 2 + (acums[b][1] - acums[a - 1][1])
	cnt2 = (acumt[d][0] - acumt[c - 1][0]) * 2 + (acumt[d][1] - acumt[c - 1][1])
	if (cnt1 - cnt2) % 3 == 0:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
ls = len(s)
lt = len(t)
sl = [0] * (ls + 1)
tl = [0] * (lt + 1)
for i in range(ls):
	if s[i] == 'A':
		sl[i + 1] = sl[i] + 1
	else:
		sl[i + 1] = sl[i] + 2
for i in range(lt):
	if t[i] == 'A':
		tl[i + 1] = tl[i] + 1
	else:
		tl[i + 1] = tl[i] + 2
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if (sl[b] - tl[d] - sl[a - 1] + tl[c - 1]) % 3 == 0:
		print('YES')
	else:
		print('NO')


import typing
import sys
import math
import collections
import bisect
import itertools
import heapq
import decimal
import copy
import operator
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.readline())

def ns():
	return list(map(int, sys.stdin.readline().split()))

def na():
	return list(map(int, sys.stdin.readline().split()))

def na1():
	return list([int(x) - 1 for x in sys.stdin.readline().split()])

def main():
	s = input()
	t = input()
	scnt = [[0, 0] for _ in range(len(s) + 1)]
	for (i, si) in enumerate(s):
		if si == 'A':
			scnt[i + 1] = [scnt[i][0] + 1, scnt[i][1]]
		else:
			scnt[i + 1] = [scnt[i][0], scnt[i][1] + 1]
	tcnt = [[0, 0] for _ in range(len(t) + 1)]
	for (i, ti) in enumerate(t):
		if ti == 'A':
			tcnt[i + 1] = [tcnt[i][0] + 1, tcnt[i][1]]
		else:
			tcnt[i + 1] = [tcnt[i][0], tcnt[i][1] + 1]
	q = ni()
	for _ in range(q):
		(a, b, c, d) = ns()
		(a, b, c, d) = (a - 1, b, c - 1, d)
		sa = scnt[b][0] - scnt[a][0]
		sb = scnt[b][1] - scnt[a][1]
		sa %= 3
		sb %= 3
		mn = min(sa, sb)
		sa -= mn
		sb -= mn
		if sa == 2:
			sb = 1
			sa = 0
		elif sb == 2:
			sa = 1
			sb = 0
		ta = tcnt[d][0] - tcnt[c][0]
		tb = tcnt[d][1] - tcnt[c][1]
		ta %= 3
		tb %= 3
		mn = min(ta, tb)
		ta -= mn
		tb -= mn
		if ta == 2:
			tb = 1
			ta = 0
		elif tb == 2:
			ta = 1
			tb = 0
		if sa == ta and sb == tb:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


S = input()
T = input()
q = int(input())
A = [list(map(int, input().split())) for _ in range(q)]
count_s = [{'A': 0, 'B': 0} for i in range(len(S))]
count_t = [{'A': 0, 'B': 0} for i in range(len(T))]
for i in range(len(S)):
	if S[i] == 'A':
		count_s[i]['A'] += 1
		if i == len(S) - 1:
			break
		count_s[i + 1] = count_s[i].copy()
	else:
		count_s[i]['B'] += 1
		if i == len(S) - 1:
			break
		count_s[i + 1] = count_s[i].copy()
for i in range(len(T)):
	if T[i] == 'A':
		count_t[i]['A'] += 1
		if i == len(T) - 1:
			break
		count_t[i + 1] = count_t[i].copy()
	else:
		count_t[i]['B'] += 1
		if i == len(T) - 1:
			break
		count_t[i + 1] = count_t[i].copy()
for i in range(q):
	if S[A[i][0] - 1] == 'A':
		count_S = {'A': count_s[A[i][1] - 1]['A'] - count_s[A[i][0] - 1]['A'] + 1, 'B': count_s[A[i][1] - 1]['B'] - count_s[A[i][0] - 1]['B']}
	else:
		count_S = {'A': count_s[A[i][1] - 1]['A'] - count_s[A[i][0] - 1]['A'], 'B': count_s[A[i][1] - 1]['B'] - count_s[A[i][0] - 1]['B'] + 1}
	if T[A[i][2] - 1] == 'A':
		count_T = {'A': count_t[A[i][3] - 1]['A'] - count_t[A[i][2] - 1]['A'] + 1, 'B': count_t[A[i][3] - 1]['B'] - count_t[A[i][2] - 1]['B']}
	else:
		count_T = {'A': count_t[A[i][3] - 1]['A'] - count_t[A[i][2] - 1]['A'], 'B': count_t[A[i][3] - 1]['B'] - count_t[A[i][2] - 1]['B'] + 1}
	if count_S['A'] - count_T['A'] > 0:
		tmp = count_S['A'] - count_T['A'] - (count_S['B'] - count_T['B'])
		if tmp % 3 == 0:
			print('YES')
		else:
			print('NO')
	else:
		tmp = count_T['A'] - count_S['A'] - (count_T['B'] - count_S['B'])
		if tmp % 3 == 0:
			print('YES')
		else:
			print('NO')


(S, T) = ([0], [0])
for (k, c) in enumerate(input()):
	S += [S[-1] + 1 + (c == 'B')]
for (k, c) in enumerate(input()):
	T += [T[-1] + 1 + (c == 'B')]
for _ in [0] * int(input()):
	(a, b, c, d) = map(int, input().split())
	print('NO' if (T[d] - T[c - 1] - S[b] + S[a - 1]) % 3 else 'YES')


from itertools import accumulate, chain
s = input()
t = input()
s_acc = list(chain((0,), accumulate((1 if c == 'A' else -1 for c in s))))
t_acc = list(chain((0,), accumulate((1 if c == 'A' else -1 for c in t))))
q = int(input())
for _ in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	x = s_acc[b] - s_acc[a - 1]
	y = t_acc[d] - t_acc[c - 1]
	print('YES' if x % 3 == y % 3 else 'NO')


import sys
read = sys.stdin.read
readline = sys.stdin.readline
s = input()
t = input()
vs = [0]
for i in s:
	if i == 'A':
		vs.append(vs[-1] + 1)
	else:
		vs.append(vs[-1] - 1)
vt = [0]
for i in t:
	if i == 'A':
		vt.append(vt[-1] + 1)
	else:
		vt.append(vt[-1] - 1)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, readline().split())
	rs = vs[b] - vs[a - 1]
	rs %= 3
	rt = vt[d] - vt[c - 1]
	rt %= 3
	if rs == rt:
		print('YES')
	else:
		print('NO')


fc = lambda x: 1 if x == 'A' else 2
s = list(map(fc, list(input())))
t = list(map(fc, list(input())))
q = int(input())
abcd = [list(map(int, input().split())) for _ in range(q)]
cs = [0]
tmp = 0
for x in s:
	tmp += x
	cs.append(tmp)
ct = [0]
tmp = 0
for x in t:
	tmp += x
	ct.append(tmp)
for (a, b, c, d) in abcd:
	if (cs[b] - cs[a - 1]) % 3 == (ct[d] - ct[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
S = list(input().rstrip())
T = list(input().rstrip())
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
Sa = []
Sb = []
for (i, s) in enumerate(S):
	if s == 'A':
		Sa.append(i)
	else:
		Sb.append(i)
Ta = []
Tb = []
for (i, t) in enumerate(T):
	if t == 'A':
		Ta.append(i)
	else:
		Tb.append(i)

def kind(La, Lb, l, r):
	ca = bisect_right(La, r) - bisect_left(La, l)
	cb = bisect_right(Lb, r) - bisect_left(Lb, l)
	return (ca + cb * 2) % 3
for (a, b, c, d) in Query:
	if kind(Sa, Sb, a - 1, b - 1) == kind(Ta, Tb, c - 1, d - 1):
		print('YES')
	else:
		print('NO')


S = input()
T = input()
N = len(S)
M = len(T)
Ss = [0] * (N + 1)
Ts = [0] * (M + 1)
for i in range(N):
	if S[i] == 'A':
		temp = 1
	else:
		temp = -1
	Ss[i + 1] = Ss[i] + temp
for i in range(M):
	if T[i] == 'A':
		temp = 1
	else:
		temp = -1
	Ts[i + 1] = Ts[i] + temp
Q = int(input())
for i in range(Q):
	(a, b, c, d) = (int(i) for i in input().split())
	if (Ss[b] - Ss[a - 1] - Ts[d] + Ts[c - 1]) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
(S_a, S_b) = ([0], [0])
(T_a, T_b) = ([0], [0])
for s in S:
	if s == 'A':
		S_a.append(S_a[-1] + 1)
		S_b.append(S_b[-1])
	if s == 'B':
		S_a.append(S_a[-1])
		S_b.append(S_b[-1] + 1)
for t in T:
	if t == 'A':
		T_a.append(T_a[-1] + 1)
		T_b.append(T_b[-1])
	if t == 'B':
		T_a.append(T_a[-1])
		T_b.append(T_b[-1] + 1)

def calc(na, nb):
	if na > nb:
		diff = na - nb
		if diff % 3 == 0:
			return ''
		elif diff % 3 % 2 == 0:
			return 'B'
		else:
			return 'A'
	else:
		diff = nb - na
		if diff % 3 == 0:
			return ''
		elif diff % 3 % 2 == 0:
			return 'A'
		else:
			return 'B'
Q = int(input())
for q in range(Q):
	(a, b, c, d) = map(int, input().split())
	sa = S_a[b] - S_a[a - 1]
	sb = S_b[b] - S_b[a - 1]
	ta = T_a[d] - T_a[c - 1]
	tb = T_b[d] - T_b[c - 1]
	SQ = calc(sa, sb)
	TQ = calc(ta, tb)
	print('YES' if SQ == TQ else 'NO')


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
s = ins()
t = ins()
sacc = [0]
for c in s:
	sacc.append(((1 if c == 'A' else 2) + sacc[-1]) % 3)
tacc = [0]
for c in t:
	tacc.append(((1 if c == 'A' else 2) + tacc[-1]) % 3)
q = inn()
for i in range(q):
	(a, b, c, d) = inm()
	print('YES' if (sacc[b] - sacc[a - 1]) % 3 == (tacc[d] - tacc[c - 1]) % 3 else 'NO')


S = input()
T = input()
cumSA = [0] * (len(S) + 1)
cumSB = [0] * (len(S) + 1)
cumTA = [0] * (len(T) + 1)
cumTB = [0] * (len(T) + 1)
for (i, s) in enumerate(S, start=1):
	cumSA[i] = cumSA[i - 1]
	cumSB[i] = cumSB[i - 1]
	if s == 'A':
		cumSA[i] += 1
	else:
		cumSB[i] += 1
for (i, t) in enumerate(T, start=1):
	cumTA[i] = cumTA[i - 1]
	cumTB[i] = cumTB[i - 1]
	if t == 'A':
		cumTA[i] += 1
	else:
		cumTB[i] += 1
Q = int(input())
ans = []
for _ in range(Q):
	(lS, rS, lT, rT) = map(int, input().split())
	sA = cumSA[rS] - cumSA[lS - 1]
	sB = cumSB[rS] - cumSB[lS - 1]
	tA = cumTA[rT] - cumTA[lT - 1]
	tB = cumTB[rT] - cumTB[lT - 1]
	if (sA - sB) % 3 == (tA - tB) % 3:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
	S = input()
	T = input()
	Scnt = [0] * (len(S) + 1)
	for i in range(len(S)):
		if S[i] == 'A':
			Scnt[i + 1] = Scnt[i] + 1
		else:
			Scnt[i + 1] = Scnt[i] + 2
	Tcnt = [0] * (len(T) + 1)
	for i in range(len(T)):
		if T[i] == 'A':
			Tcnt[i + 1] = Tcnt[i] + 1
		else:
			Tcnt[i + 1] = Tcnt[i] + 2
	Q = int(input())
	for _ in range(Q):
		(a, b, c, d) = map(int, input().split())
		a -= 1
		c -= 1
		if (Scnt[b] - Scnt[a] - Tcnt[d] + Tcnt[c]) % 3 == 0:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


S = input()
T = input()
Q = int(input())
qs = [tuple(map(int, input().split())) for i in range(Q)]
sas = [0]
sbs = [0]
for c in S:
	a = int(c == 'A')
	sas.append(sas[-1] + a)
	sbs.append(sbs[-1] + (a ^ 1))
tas = [0]
tbs = [0]
for c in T:
	a = int(c == 'A')
	tas.append(tas[-1] + a)
	tbs.append(tbs[-1] + (a ^ 1))
ans = []
for (a, b, c, d) in qs:
	sa = sas[b] - sas[a - 1]
	sb = sbs[b] - sbs[a - 1]
	ta = tas[d] - tas[c - 1]
	tb = tbs[d] - tbs[c - 1]
	s = (sb - sa) % 3
	t = (tb - ta) % 3
	ans.append('YES' if s == t else 'NO')
print(*ans, sep='\n')


s = input()
t = input()
sm = 0
ss = []
for i in s:
	sm += (i == 'A') * 2 - 1
	ss.append(sm)
ss.append(0)
sm = 0
ts = []
for i in t:
	sm += (i == 'A') * 2 - 1
	ts.append(sm)
ts.append(0)
q = int(input())
for i in range(q):
	inp = list(map(int, input().split()))
	if (ss[inp[1] - 1] - ss[inp[0] - 2]) % 3 == (ts[inp[3] - 1] - ts[inp[2] - 2]) % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
q = int(input())
s = [0] * len(S)
t = [0] * len(T)
for (i, x) in enumerate(S):
	if x == 'A':
		s[i] += 1
for (i, x) in enumerate(T):
	if x == 'A':
		t[i] += 1
ss = [0] * (len(S) + 1)
for (i, x) in enumerate(s):
	ss[i + 1] = s[i] + ss[i]
tt = [0] * (len(T) + 1)
for (i, x) in enumerate(t):
	tt[i + 1] = t[i] + tt[i]
for i in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	k = ss[b] - ss[a - 1]
	l = tt[d] - tt[c - 1]
	k += (b - a + 1 - k) * 2
	l += (d - c + 1 - l) * 2
	if abs(k - l) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
Q = int(input())
N = len(S)
M = len(T)
accSA = [0] * (N + 1)
accSB = [0] * (N + 1)
accTA = [0] * (M + 1)
accTB = [0] * (M + 1)
for (i, s) in enumerate(S, start=1):
	accSA[i] = accSA[i - 1]
	accSB[i] = accSB[i - 1]
	if s == 'A':
		accSA[i] += 1
	else:
		accSB[i] += 1
for (i, t) in enumerate(T, start=1):
	accTA[i] = accTA[i - 1]
	accTB[i] = accTB[i - 1]
	if t == 'A':
		accTA[i] += 1
	else:
		accTB[i] += 1
ans = []
for _ in range(Q):
	(leftS, rightS, leftT, rightT) = map(int, input().split())
	sA = accSA[rightS] - accSA[leftS - 1]
	sB = accSB[rightS] - accSB[leftS - 1]
	tA = accTA[rightT] - accTA[leftT - 1]
	tB = accTB[rightT] - accTB[leftT - 1]
	if (sA + sB * 2) % 3 == (tA + tB * 2) % 3:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


import sys
import collections
input = sys.stdin.readline

def main():
	S = input().strip()
	T = input().strip()
	Q = int(input())
	ABCD = [[int(x) for x in input().split()] for _ in range(Q)]
	TAruiseki = [0] * (len(S) + 1)
	TBruiseki = [0] * (len(S) + 1)
	SAruiseki = [0] * (len(S) + 1)
	SBruiseki = [0] * (len(S) + 1)
	for (i, s) in enumerate(S):
		if s == 'A':
			SAruiseki[i + 1] += 1
			SAruiseki[i + 1] += SAruiseki[i]
			SBruiseki[i + 1] += SBruiseki[i]
		else:
			SBruiseki[i + 1] += 1
			SBruiseki[i + 1] += SBruiseki[i]
			SAruiseki[i + 1] += SAruiseki[i]
	for (i, t) in enumerate(T):
		if t == 'A':
			TAruiseki[i + 1] += 1
			TAruiseki[i + 1] += TAruiseki[i]
			TBruiseki[i + 1] += TBruiseki[i]
		else:
			TBruiseki[i + 1] += 1
			TBruiseki[i + 1] += TBruiseki[i]
			TAruiseki[i + 1] += TAruiseki[i]
	for (a, b, c, d) in ABCD:
		sacnt = SAruiseki[b] - SAruiseki[a - 1]
		sbcnt = SBruiseki[b] - SBruiseki[a - 1]
		tacnt = TAruiseki[d] - TAruiseki[c - 1]
		tbcnt = TBruiseki[d] - TBruiseki[c - 1]
		if (sacnt - tacnt) % 3 == (sbcnt - tbcnt) % 3:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
yes = 'YES'
no = 'NO'
s = input()
t = input()
ls = [0]
lt = [0]
p = 0
for c in s:
	if c == 'A':
		p += 1
	else:
		p -= 1
	ls.append(p)
p = 0
for c in t:
	if c == 'A':
		p += 1
	else:
		p -= 1
	lt.append(p)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if (ls[b] - ls[a - 1]) % 3 == (lt[d] - lt[c - 1]) % 3:
		print(yes)
	else:
		print(no)


from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
	return list(map(int, sys.stdin.readline().split()))

def I():
	return int(sys.stdin.readline())

def LS():
	return list(map(list, sys.stdin.readline().split()))

def S():
	return list(sys.stdin.readline())[:-1]

def IR(n):
	l = [None for i in range(n)]
	for i in range(n):
		l[i] = I()
	return l

def LIR(n):
	l = [None for i in range(n)]
	for i in range(n):
		l[i] = LI()
	return l

def SR(n):
	l = [None for i in range(n)]
	for i in range(n):
		l[i] = S()
	return l

def LSR(n):
	l = [None for i in range(n)]
	for i in range(n):
		l[i] = LS()
	return l
sys.setrecursionlimit(1000000)
mod = 1000000007

def A():
	x = S()
	s = 0
	ans = len(x)
	for i in x:
		if i == 'S':
			s += 1
		elif s > 0:
			s -= 1
			ans -= 2
	print(ans)
	return

def B():
	n = I()
	a = LI()
	f = [0 for i in range(n + 1)]
	for i in range(n):
		f[a[i]] = i
	l = [i for i in range(n + 1)]
	r = [i for i in range(n + 1)]
	ans = 0
	for i in range(1, n + 1)[::-1]:
		j = f[i]
		ans += (j - l[j] + 1) * (r[j] - j + 1) * i
		l[r[j] + 1] = l[j]
		r[l[j] - 1] = r[j]
	print(ans)
	return

def C():
	(n, x) = LI()
	if x == 1 or x == 2 * n - 1:
		print('No')
		quit()
	else:
		ans = [i + 1 for i in range(2 * n - 1)]
		k = x - n
		if k < 0:
			ans = ans[2 * n - 1 + k:] + ans[:2 * n - 1 + k]
		if k > 0:
			ans = ans[k:] + ans[:k]
		print('Yes')
		for i in ans:
			print(i)
	return

def D():
	s = S()
	t = S()
	n = len(s)
	m = len(t)
	fs = [1 if s[i] == 'A' else 2 for i in range(n)]
	ft = [1 if t[i] == 'A' else 2 for i in range(m)]
	for i in range(n - 1):
		fs[i + 1] += fs[i]
		fs[i + 1] %= mod
	for i in range(m - 1):
		ft[i + 1] += ft[i]
		ft[i + 1] %= mod
	fs.insert(0, 0)
	ft.insert(0, 0)
	q = I()
	for i in range(q):
		(a, b, c, d) = LI()
		a -= 1
		c -= 1
		if (fs[b] - fs[a]) % 3 == (ft[d] - ft[c]) % 3:
			print('YES')
		else:
			print('NO')
	return

def E():
	return

def F():
	return

def G():
	return

def H():
	return
D()


S = input()
T = input()
q = int(input())
SA = []
SB = []
cnt_a = 0
cnt_b = 0
for s in S:
	if s == 'A':
		cnt_a += 1
	else:
		cnt_b += 1
	SA.append(cnt_a)
	SB.append(cnt_b)
TA = []
TB = []
cnt_a = 0
cnt_b = 0
for t in T:
	if t == 'A':
		cnt_a += 1
	else:
		cnt_b += 1
	TA.append(cnt_a)
	TB.append(cnt_b)

def check(a, b, c, d):
	sa = SA[b - 1]
	sb = SB[b - 1]
	if a >= 2:
		sa -= SA[a - 2]
		sb -= SB[a - 2]
	ta = TA[d - 1]
	tb = TB[d - 1]
	if c >= 2:
		ta -= TA[c - 2]
		tb -= TB[c - 2]
	sb += 2 * sa
	sb %= 3
	tb += 2 * ta
	tb %= 3
	return sb == tb
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	if check(a, b, c, d):
		print('YES')
	else:
		print('NO')


s = input()
t = input()
q = int(input())
sa_pre = [s[i] == 'A' for i in range(len(s))]
ta_pre = [t[i] == 'A' for i in range(len(t))]
sa = [0, sa_pre[0]]
ta = [0, ta_pre[0]]
for i in range(1, len(s)):
	sa.append(sa[-1] + sa_pre[i])
for i in range(1, len(t)):
	ta.append(ta[-1] + ta_pre[i])

def check(a, b, c, d):
	xa = sa[b] - sa[a - 1]
	ya = ta[d] - ta[c - 1]
	if (2 * xa - (b - a + 1)) % 3 == (2 * ya - (d - c + 1)) % 3:
		print('YES')
		return
	else:
		print('NO')
		return
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	check(a, b, c, d)


s = input()
t = input()
q = int(input())
(sl, tl) = (len(s), len(t))
(sa, sb, ta, tb) = ([0] * (sl + 1), [0] * (sl + 1), [0] * (tl + 1), [0] * (tl + 1))
for i in range(sl):
	if s[i] == 'A':
		(sa[i + 1], sb[i + 1]) = (sa[i] + 1, sb[i])
	else:
		(sa[i + 1], sb[i + 1]) = (sa[i], sb[i] + 1)
for i in range(tl):
	if t[i] == 'A':
		(ta[i + 1], tb[i + 1]) = (ta[i] + 1, tb[i])
	else:
		(ta[i + 1], tb[i + 1]) = (ta[i], tb[i] + 1)
for _ in range(q):
	(a, b, c, d) = (int(i) for i in input().split())
	if (sa[b] - sa[a - 1] - sb[b] + sb[a - 1] - ta[d] + ta[c - 1] + tb[d] - tb[c - 1]) % 3:
		print('NO')
	else:
		print('YES')


S = input()
T = input()
N = len(S)
M = len(T)
U = [0 for i in range(N + 1)]
V = [0 for i in range(M + 1)]
for i in range(N):
	if S[i] == 'A':
		U[i + 1] = (U[i] + 1) % 3
	else:
		U[i + 1] = (U[i] - 1) % 3
for i in range(M):
	if T[i] == 'A':
		V[i + 1] = (V[i] + 1) % 3
	else:
		V[i + 1] = (V[i] - 1) % 3
q = int(input())
O = ['' for i in range(q)]
for inp in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	if (U[b] - U[a - 1] - V[d] + V[c - 1]) % 3 == 0:
		O[inp] = 'YES'
	else:
		O[inp] = 'NO'
for i in O:
	print(i)


from itertools import accumulate
s = input()
t = input()
q = int(input())
abcd = [tuple(map(int, input().split())) for i in range(q)]
s_number = [2 if ab == 'B' else 1 for ab in s]
t_number = [2 if ab == 'B' else 1 for ab in t]
s_sum = [0] + s_number
s_sum = list(accumulate(s_sum))
t_sum = [0] + t_number
t_sum = list(accumulate(t_sum))
for (a, b, c, d) in abcd:
	s_i = s_sum[b] - s_sum[a - 1]
	t_i = t_sum[d] - t_sum[c - 1]
	if s_i % 3 == t_i % 3:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	s = SI()
	t = SI()
	s = [0] + [x for x in accumulate([1 if c == 'A' else 2 for c in s])]
	t = [0] + [x for x in accumulate([1 if c == 'A' else 2 for c in t])]
	q = II()
	for _ in range(q):
		(a, b, c, d) = MI()
		if (s[b] - s[a - 1]) % 3 == (t[d] - t[c - 1]) % 3:
			print('YES')
		else:
			print('NO')
main()


s = input()
t = input()
q = int(input())
len_s = len(s)
len_t = len(t)
s_counter = [0] * (len_s + 1)
s_temp = 0
for i in range(len_s):
	if s[i] == 'A':
		s_temp += 1
	s_counter[i + 1] = s_temp
t_counter = [0] * (len_t + 1)
t_temp = 0
for i in range(len_t):
	if t[i] == 'A':
		t_temp += 1
	t_counter[i + 1] = t_temp
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	x = s_counter[b] - s_counter[a - 1]
	y = t_counter[d] - t_counter[c - 1]
	print(['NO', 'YES'][(x + b - a + 1 - (y + d - c + 1)) % 3 == 0])


def i1():
	return int(input())

def i2():
	return [int(i) for i in input().split()]
S = input()
T = input()
s = [0 for i in range(len(S))]
for i in range(len(s)):
	if S[i] == 'B':
		s[i] = 2
	else:
		s[i] = 1
t = [0 for i in range(len(T))]
for i in range(len(t)):
	if T[i] == 'B':
		t[i] = 2
	else:
		t[i] = 1
for i in range(len(s) - 1):
	s[i + 1] += s[i]
for i in range(len(t) - 1):
	t[i + 1] += t[i]
q = i1()
s = [0] + s
t = [0] + t
for i in range(q):
	[a, b, c, d] = i2()
	if (s[b] - s[a - 1]) % 3 == (t[d] - t[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


s = input()
t = input()
ssum = [0 for _ in range(len(s) + 1)]
for i in range(len(s)):
	ssum[i + 1] = ssum[i] + (s[i] == 'A')
tsum = [0 for _ in range(len(t) + 1)]
for i in range(len(t)):
	tsum[i + 1] = tsum[i] + (t[i] == 'A')
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	cnts = (b - a + 1) * 2 - (ssum[b] - ssum[a - 1])
	cntt = (d - c + 1) * 2 - (tsum[d] - tsum[c - 1])
	print('YES' if cnts % 3 == cntt % 3 else 'NO')


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 5)

def li():
	return map(int, stdin.readline().split())

def li_():
	return map(lambda x: int(x) - 1, stdin.readline().split())

def lf():
	return map(float, stdin.readline().split())

def ls():
	return stdin.readline().split()

def ns():
	return stdin.readline().rstrip()

def lc():
	return list(ns())

def ni():
	return int(stdin.readline())

def nf():
	return float(stdin.readline())
s = ns()
t = ns()
q = ni()
sa = [0]
sb = [0]
ta = [0]
tb = [0]
for si in s:
	if si == 'A':
		sa.append(sa[-1] + 1)
		sb.append(sb[-1])
	else:
		sa.append(sa[-1])
		sb.append(sb[-1] + 1)
for ti in t:
	if ti == 'A':
		ta.append(ta[-1] + 1)
		tb.append(tb[-1])
	else:
		ta.append(ta[-1])
		tb.append(tb[-1] + 1)
for _ in range(q):
	(a, b, c, d) = li()
	sanum = sa[b] - sa[a - 1]
	sbnum = sb[b] - sb[a - 1]
	tanum = ta[d] - ta[c - 1]
	tbnum = tb[d] - tb[c - 1]
	sanum += 2 * sbnum
	tanum += 2 * tbnum
	if sanum % 3 == tanum % 3:
		print('YES')
	else:
		print('NO')


import math
import queue
from collections import deque, defaultdict
import heapq as hpq
from sys import stdin, setrecursionlimit
ipt = stdin.readline
setrecursionlimit(10 ** 7)

def main():
	s = input()
	t = input()
	ns = len(s) + 1
	nt = len(t) + 1
	ssa = [0] * ns
	ssb = [0] * ns
	sta = [0] * nt
	stb = [0] * nt
	for (i, si) in enumerate(s):
		if si == 'A':
			da = 1
			db = 0
		else:
			da = 0
			db = 1
		ssa[i + 1] = ssa[i] + da
		ssb[i + 1] = ssb[i] + db
	for (i, ti) in enumerate(t):
		if ti == 'A':
			da = 1
			db = 0
		else:
			da = 0
			db = 1
		sta[i + 1] = sta[i] + da
		stb[i + 1] = stb[i] + db
	q = int(ipt())
	for _ in range(q):
		(a, b, c, d) = list(map(int, ipt().split()))
		da = ssa[b] - ssa[a - 1] - sta[d] + sta[c - 1]
		db = ssb[b] - ssb[a - 1] - stb[d] + stb[c - 1]
		if (da - db) % 3 == 0:
			print('YES')
		else:
			print('NO')
	return

def __starting_point():
	main()
__starting_point()


S = input()
T = input()
Q = int(input())
qs = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(Q)]
smem = [0]
for c in S:
	if c == 'A':
		smem.append(smem[-1] + 1)
	else:
		smem.append(smem[-1] - 1)
tmem = [0]
for c in T:
	if c == 'A':
		tmem.append(tmem[-1] + 1)
	else:
		tmem.append(tmem[-1] - 1)
anss = []
for (s1, s2, t1, t2) in qs:
	a = smem[s2 + 1] - smem[s1]
	b = tmem[t2 + 1] - tmem[t1]
	if a % 3 == b % 3:
		anss.append('YES')
	else:
		anss.append('NO')
print(*anss, sep='\n')


S = input()
T = input()
Q = int(input())
ABCD = [tuple(map(int, input().split())) for i in range(Q)]
csa = [0]
csb = [0]
for c in S:
	csa.append(csa[-1] + (c == 'A'))
	csb.append(csb[-1] + (c == 'B'))
cta = [0]
ctb = [0]
for c in T:
	cta.append(cta[-1] + (c == 'A'))
	ctb.append(ctb[-1] + (c == 'B'))
ans = []
for (a, b, c, d) in ABCD:
	a -= 1
	c -= 1
	sa = csa[b] - csa[a]
	sb = csb[b] - csb[a]
	ta = cta[d] - cta[c]
	tb = ctb[d] - ctb[c]
	s = (sb - sa) % 3
	t = (tb - ta) % 3
	ans.append('YES' if s == t else 'NO')
print(*ans, sep='\n')


S = input()
T = input()
LS = [[0, 0] for _ in range(len(S) + 1)]
LT = [[0, 0] for _ in range(len(S) + 1)]
for (i, s) in enumerate(S):
	LS[i + 1] = list(LS[i])
	if s == 'A':
		LS[i + 1][0] += 1
	if s == 'B':
		LS[i + 1][1] += 1
for (i, t) in enumerate(T):
	LT[i + 1] = list(LT[i])
	if t == 'A':
		LT[i + 1][0] += 1
	if t == 'B':
		LT[i + 1][1] += 1
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	sa = (LS[b][0] - LS[a - 1][0]) % 3
	sb = (LS[b][1] - LS[a - 1][1]) % 3
	ta = (LT[d][0] - LT[c - 1][0]) % 3
	tb = (LT[d][1] - LT[c - 1][1]) % 3
	print('YES' if (sa - sb) % 3 == (ta - tb) % 3 else 'NO')


def check(ssum, tsum, a, b, c, d):
	return (ssum[b] - ssum[a - 1] - (tsum[d] - tsum[c - 1])) % 3 == 0
s = input()
t = input()
q = int(input())
a = [[int(i) for i in input().split()] for j in range(q)]
ssum = [0]
tsum = [0]
for i in range(len(s)):
	if s[i] == 'A':
		temp = 1
	else:
		temp = 2
	ssum.append(ssum[i] + temp)
for i in range(len(t)):
	if t[i] == 'A':
		temp = 1
	else:
		temp = 2
	tsum.append(tsum[i] + temp)
for i in range(q):
	if check(ssum, tsum, a[i][0], a[i][1], a[i][2], a[i][3]):
		print('YES')
	else:
		print('NO')


S = input()
T = input()
q = int(input())
ans = []
cnt = 0
sbs = [0]
for c in S:
	if c == 'B':
		cnt += 1
	sbs.append(cnt)
cnt = 0
tbs = [0]
for c in T:
	if c == 'B':
		cnt += 1
	tbs.append(cnt)
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	sb = sbs[b] - sbs[a - 1]
	tb = tbs[d] - tbs[c - 1]
	sa = b - a + sb
	if tb % 2 == 0:
		ta = d - c - tb + tb // 2
	else:
		ta = d - c - tb + (tb + 3) // 2
	if (sa - ta) % 3 == 0:
		ans.append('YES')
	else:
		ans.append('NO')
for yn in ans:
	print(yn)


S = input()
T = input()
cum_s = [(0, 0)]
cum_t = [(0, 0)]
for i in range(len(S)):
	(p, q) = cum_s[-1]
	if S[i] == 'A':
		cum_s.append((p + 1, q))
	else:
		cum_s.append((p, q + 1))
for i in range(len(T)):
	(p, q) = cum_t[-1]
	if T[i] == 'A':
		cum_t.append((p + 1, q))
	else:
		cum_t.append((p, q + 1))
Q = int(input())
for _ in range(Q):
	(a, b, c, d) = map(int, input().split())
	sp = cum_s[b][0] - cum_s[a - 1][0]
	sq = cum_s[b][1] - cum_s[a - 1][1]
	tp = cum_t[d][0] - cum_t[c - 1][0]
	tq = cum_t[d][1] - cum_t[c - 1][1]
	sp += sq * 2
	tp += tq * 2
	if sp % 3 == tp % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()

def pre_(X):
	d = dict()
	d[0] = 0
	tmp = 0
	for (i, s) in enumerate(X):
		if s == 'A':
			tmp += 1
		else:
			tmp += 2
		d[i + 1] = tmp
	return d
Sx = pre_(S)
Tx = pre_(T)
for (a, b, c, d) in [list(map(int, input().split())) for _ in range(int(input()))]:
	print('YES' if (Sx[a - 1] - Sx[b] - (Tx[c - 1] - Tx[d])) % 3 == 0 else 'NO')


s = input().rstrip()
t = input().rstrip()
s_anum = [0] * len(s)
t_anum = [0] * len(s)
val = 0
for (i, ch) in enumerate(s):
	if ch == 'A':
		val += 1
	elif ch == 'B':
		val += 2
	s_anum[i] = val % 3
s_anum = [0] + s_anum
val = 0
for (i, ch) in enumerate(t):
	if ch == 'A':
		val += 1
	elif ch == 'B':
		val += 2
	t_anum[i] = val % 3
t_anum = [0] + t_anum
q = int(input())
for i in range(q):
	(a, b, c, d) = [int(item) for item in input().split()]
	if (s_anum[b] - s_anum[a - 1] + 3) % 3 == (t_anum[d] - t_anum[c - 1] + 3) % 3:
		print('YES')
	else:
		print('NO')


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inpl():
	return list(map(int, input().split()))

def inpl_s():
	return list(input().split())
S = input()
T = input()
q = int(input())
tmp = 0
S_SUM = [0]
for s in S:
	if s == 'A':
		tmp += 2
	else:
		tmp += 1
	S_SUM.append(tmp)
T_SUM = [0]
tmp = 0
for t in T:
	if t == 'A':
		tmp += 2
	else:
		tmp += 1
	T_SUM.append(tmp)
for i in range(q):
	(a, b, c, d) = inpl()
	sa = S_SUM[b] - S_SUM[a - 1] - (T_SUM[d] - T_SUM[c - 1])
	if sa % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
s = readline().strip()
t = readline().strip()
q = int(readline())
abcd = list(map(int, read().split()))
cumsum_s = [0] * (len(s) + 1)
cumsum_t = [0] * (len(t) + 1)
for (cs, st) in zip([cumsum_s, cumsum_t], [s, t]):
	for (i, ch) in enumerate(st, 1):
		cs[i] = cs[i - 1] + (1 if ch == 'A' else 2)
ans = []
it = iter(abcd)
for (a, b, c, d) in zip(it, it, it, it):
	num1 = cumsum_s[b] - cumsum_s[a - 1]
	num2 = cumsum_t[d] - cumsum_t[c - 1]
	if (num1 - num2) % 3 == 0:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


s = input().strip()
t = input().strip()
SX = [0]
for c in s:
	if c == 'A':
		SX.append(SX[-1] + 1)
	else:
		SX.append(SX[-1])
TX = [0]
for c in t:
	if c == 'A':
		TX.append(TX[-1] + 1)
	else:
		TX.append(TX[-1])
(Q,) = list(map(int, input().split()))
for _ in range(Q):
	(a, b, c, d) = list(map(int, input().split()))
	sa = SX[b] - SX[a - 1]
	sb = b - a + 1 - sa
	ta = TX[d] - TX[c - 1]
	tb = d - c + 1 - ta
	if (sa - sb) % 3 == (ta - tb) % 3:
		print('YES')
	else:
		print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def main():
	s = S()
	t = S()
	sl = len(s)
	tl = len(t)
	c = 0
	sa = []
	for i in range(sl):
		c += 1 if s[i] == 'A' else 2
		sa.append(c)
	c = 0
	ta = []
	for i in range(tl):
		c += 1 if t[i] == 'A' else 2
		ta.append(c)
	r = []
	q = I()
	for _ in range(q):
		(a, b, c, d) = LI()
		st = sa[b - 1]
		if a > 1:
			st -= sa[a - 2]
		tt = ta[d - 1]
		if c > 1:
			tt -= ta[c - 2]
		if st % 3 == tt % 3:
			r.append('YES')
		else:
			r.append('NO')
	return '\n'.join(r)
print(main())


S = input()
T = input()
q = int(input())
abcd = [[int(i) for i in input().split()] for _ in range(q)]
sdp = [(0, 0)]
tdp = [(0, 0)]
for s in S:
	(a, b) = sdp[-1]
	if s == 'A':
		sdp.append((a + 1, b))
	else:
		sdp.append((a, b + 1))
for t in T:
	(a, b) = tdp[-1]
	if t == 'A':
		tdp.append((a + 1, b))
	else:
		tdp.append((a, b + 1))
for (a, b, c, d) in abcd:
	sa = sdp[b][0] - sdp[a - 1][0]
	sb = sdp[b][1] - sdp[a - 1][1]
	ta = tdp[d][0] - tdp[c - 1][0]
	tb = tdp[d][1] - tdp[c - 1][1]
	tb -= ta - sa
	if abs(sb - tb) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
S = input()
T = input()
q = int(input())
ls = len(S)
lt = len(T)
cs_s = [0] * (ls + 1)
cs_t = [0] * (lt + 1)
for i in range(ls):
	tmp = 1 if S[i] == 'A' else -1
	cs_s[i + 1] = cs_s[i] + tmp
for i in range(lt):
	tmp = 1 if T[i] == 'A' else -1
	cs_t[i + 1] = cs_t[i] + tmp
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if (cs_s[b] - cs_s[a - 1]) % 3 == (cs_t[d] - cs_t[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
s_rui = [0]
t_rui = [0]
for s in S:
	if s == 'A':
		s_rui.append(s_rui[-1] + 1)
	else:
		s_rui.append(s_rui[-1] + 2)
for t in T:
	if t == 'A':
		t_rui.append(t_rui[-1] + 1)
	else:
		t_rui.append(t_rui[-1] + 2)
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	ss = s_rui[b] - s_rui[a - 1]
	tt = t_rui[d] - t_rui[c - 1]
	if ss % 3 == tt % 3:
		print('YES')
	else:
		print('NO')


S = input()
T = input()
q = int(input())
SS = [0]
TT = [0]
for i in S:
	if i == 'A':
		SS.append(1 + SS[-1])
	else:
		SS.append(2 + SS[-1])
for i in T:
	if i == 'A':
		TT.append(1 + TT[-1])
	else:
		TT.append(2 + TT[-1])
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	if (SS[b] - SS[a - 1]) % 3 == (TT[d] - TT[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	S = [1 if s == 'A' else 2 for s in input()]
	T = [1 if s == 'A' else 2 for s in input()]
	m = len(S)
	n = len(T)
	CS = [0] * (m + 1)
	for i in range(m):
		CS[i + 1] = CS[i] + S[i]
	CT = [0] * (n + 1)
	for i in range(n):
		CT[i + 1] = CT[i] + T[i]
	for _ in range(int(input())):
		(a, b, c, d) = map(int, input().split())
		a -= 1
		c -= 1
		k = abs(CS[b] - CS[a] - (CT[d] - CT[c]))
		print('YES' if k % 3 == 0 else 'NO')
resolve()


Ss = input()
Ts = input()
q = int(input())
querys = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(q)]

def countA(Cs):
	numAs = [0] * (len(Cs) + 1)
	for (i, C) in enumerate(Cs, 1):
		if C == 'A':
			numAs[i] = numAs[i - 1] + 1
		else:
			numAs[i] = numAs[i - 1]
	return numAs
numASs = countA(Ss)
numATs = countA(Ts)
for (a, b, c, d) in querys:
	lenS = b - a + 1
	numAS = numASs[b + 1] - numASs[a]
	lenT = d - c + 1
	numAT = numATs[d + 1] - numATs[c]
	if (numAS - (lenS - numAS) - (numAT - (lenT - numAT))) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = [input() for i in range(2)]
q = int(input())
ABCD = [list(map(int, input().split())) for i in range(q)]
p = [[0] for i in range(2)]
for i in range(2):
	for (j, s) in enumerate(S[i]):
		if s == 'A':
			p[i].append(p[i][-1] + 1)
		else:
			p[i].append(p[i][-1] + 2)
for (a, b, c, d) in ABCD:
	print(['NO', 'YES'][(p[0][b] - p[0][a - 1]) % 3 == (p[1][d] - p[1][c - 1]) % 3])


S = input()
T = input()
ms = [0]
for s in S:
	if s == 'A':
		ms.append(ms[-1] + 1)
	else:
		ms.append(ms[-1] - 1)
mt = [0]
for t in T:
	if t == 'A':
		mt.append(mt[-1] + 1)
	else:
		mt.append(mt[-1] - 1)
q = int(input())
for _ in range(q):
	(a, b, c, d) = map(int, input().split())
	if (ms[b] - ms[a - 1]) % 3 == (mt[d] - mt[c - 1]) % 3:
		print('YES')
	else:
		print('NO')


import numpy as np
S = list(input())
T = list(input())
count_A_S = np.r_[[0], np.array(S) == 'A']
count_A_S = count_A_S.cumsum()
count_B_S = np.r_[[0], np.array(S) == 'B']
count_B_S = count_B_S.cumsum()
count_A_T = np.r_[[0], np.array(T) == 'A']
count_A_T = count_A_T.cumsum()
count_B_T = np.r_[[0], np.array(T) == 'B']
count_B_T = count_B_T.cumsum()

def check(a1, b1, a2, b2):
	if a1 < a2:
		if b1 < b2:
			diff1 = a2 - a1
			diff2 = b2 - b1
			diff = abs(diff1 - diff2)
		else:
			diff = b1 - b2 + a2 - a1
	elif b1 < b2:
		diff = a1 - a2 + b2 - b1
	else:
		diff1 = a1 - a2
		diff2 = b1 - b2
		diff = abs(diff1 - diff2)
	if diff % 3 == 0:
		return 'YES'
	else:
		return 'NO'
q = int(input())
ans = []
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	num_a_s = count_A_S[b] - count_A_S[a - 1]
	num_b_s = count_B_S[b] - count_B_S[a - 1]
	num_a_t = count_A_T[d] - count_A_T[c - 1]
	num_b_t = count_B_T[d] - count_B_T[c - 1]
	ans.append(check(num_a_s, num_b_s, num_a_t, num_b_t))
print(*ans, sep='\n')


(s, t, _, *z) = open(0)
(v, w) = ([0], [0])
for c in s:
	v += (v[-1] + (c < 'B' or 2),)
for c in t:
	w += (w[-1] + (c < 'B' or 2),)
for x in z:
	(a, b, c, d) = map(int, x.split())
	print('YNEOS'[(v[b] - v[a - 1]) % 3 != (w[d] - w[c - 1]) % 3::2])


def main():

	def plus(a, b):
		if a == '':
			return b
		elif b == '':
			return a
		elif a == 'A':
			if b == 'A':
				return 'B'
			else:
				return ''
		elif b == 'A':
			return ''
		else:
			return 'A'

	def minus(a, b):
		if b == 'A':
			b = 'B'
		elif b == 'B':
			b = 'A'
		return plus(a, b)
	dp1 = ['']
	dp2 = ['']
	s = input()
	t = input()
	q = int(input())
	abcd = [list(map(int, input().split())) for _ in [0] * q]
	for i in s:
		dp1.append(plus(dp1[-1], i))
	for i in t:
		dp2.append(plus(dp2[-1], i))
	for (a, b, c, d) in abcd:
		(a, b, c, d) = (dp1[a - 1], dp1[b], dp2[c - 1], dp2[d])
		print(['NO', 'YES'][minus(b, a) == minus(d, c)])
main()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
import math
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
MOD = 10 ** 9 + 7
INF = float('inf')
AZ = 'abcdefghijklmnopqrstuvwxyz'

def I():
	return int(input().strip())

def S():
	return input().strip()

def IL():
	return list(map(int, input().split()))

def SL():
	return list(map(str, input().split()))

def ILs(n):
	return list((int(input()) for _ in range(n)))

def SLs(n):
	return list((input().strip() for _ in range(n)))

def ILL(n):
	return [list(map(int, input().split())) for _ in range(n)]

def SLL(n):
	return [list(map(str, input().split())) for _ in range(n)]

def DD(arg):
	return defaultdict(arg)

def inv(n):
	return pow(n, MOD - 2, MOD)
kaijo_memo = []

def kaijo(n):
	if len(kaijo_memo) > n:
		return kaijo_memo[n]
	if len(kaijo_memo) == 0:
		kaijo_memo.append(1)
	while len(kaijo_memo) <= n:
		kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
	return kaijo_memo[n]
gyaku_kaijo_memo = []

def gyaku_kaijo(n):
	if len(gyaku_kaijo_memo) > n:
		return gyaku_kaijo_memo[n]
	if len(gyaku_kaijo_memo) == 0:
		gyaku_kaijo_memo.append(1)
	while len(gyaku_kaijo_memo) <= n:
		gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD)
	return gyaku_kaijo_memo[n]

def nCr(n, r):
	if n == r:
		return 1
	if n < r or r < 0:
		return 0
	ret = 1
	ret = ret * kaijo(n) % MOD
	ret = ret * gyaku_kaijo(r) % MOD
	ret = ret * gyaku_kaijo(n - r) % MOD
	return ret

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
		if temp % i == 0:
			cnt = 0
			while temp % i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors

def make_primes(N):
	max = int(math.sqrt(N))
	seachList = [i for i in range(2, N + 1)]
	primeNum = []
	while seachList[0] <= max:
		primeNum.append(seachList[0])
		tmp = seachList[0]
		seachList = [i for i in seachList if i % tmp != 0]
	primeNum.extend(seachList)
	return primeNum

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)

def count_bit(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count

def base_10_to_n(X, n):
	if X // n:
		return base_10_to_n(X // n, n) + [X % n]
	return [X % n]

def base_n_to_10(X, n):
	return sum((int(str(X)[-i - 1]) * n ** i for i in range(len(str(X)))))

def base_10_to_n_without_0(X, n):
	X -= 1
	if X // n:
		return base_10_to_n_without_0(X // n, n) + [X % n]
	return [X % n]

def int_log(a, n):
	count = 0
	while n >= a:
		n //= a
		count += 1
	return count
S = input().strip()
T = input().strip()
accS = [0]
for s in S:
	if s == 'A':
		accS.append((accS[-1] + 1) % 3)
	else:
		accS.append((accS[-1] + 2) % 3)
accT = [0]
for t in T:
	if t == 'A':
		accT.append((accT[-1] + 1) % 3)
	else:
		accT.append((accT[-1] + 2) % 3)
Q = I()
for _ in range(Q):
	(a, b, c, d) = IL()
	if (accS[b] - accS[a - 1] - (accT[d] - accT[c - 1])) % 3:
		print('NO')
	else:
		print('YES')


import sys
F = sys.stdin
S = F.readline().replace('A', '1').replace('B', '2').strip('\n')
T = F.readline().replace('A', '1').replace('B', '2').strip('\n')
sSum = [0] * (len(S) + 1)
tSum = [0] * (len(T) + 1)
for i in range(len(S)):
	sSum[i + 1] = sSum[i] + int(S[i])
for i in range(len(T)):
	tSum[i + 1] = tSum[i] + int(T[i])
Ans = ''
Q = int(F.readline().strip('\n'))
for _ in range(Q):
	(a, b, c, d) = map(int, F.readline().strip('\n').split(' '))
	if (sSum[b] - sSum[a - 1]) % 3 == (tSum[d] - tSum[c - 1]) % 3:
		Ans += 'YES\n'
	else:
		Ans += 'NO\n'
print(Ans)


(S, T, q, *L) = open(0).read().split()
sa = [0]
sb = [0]
ta = [0]
tb = [0]
for c in S:
	if c == 'A':
		sa.append(sa[-1] + 1)
		sb.append(sb[-1])
	else:
		sa.append(sa[-1])
		sb.append(sb[-1] + 1)
for c in T:
	if c == 'A':
		ta.append(ta[-1] + 1)
		tb.append(tb[-1])
	else:
		ta.append(ta[-1])
		tb.append(tb[-1] + 1)
for (a, b, c, d) in zip(*[iter(map(int, L))] * 4):
	nsa = sa[b] - sa[a - 1]
	nsb = sb[b] - sb[a - 1]
	nta = ta[d] - ta[c - 1]
	ntb = tb[d] - tb[c - 1]
	mb = ntb - nsb
	ma = nta - nsa
	if (2 * mb + ma) % 3 == (2 * ma + mb) % 3 == 0:
		print('YES')
	else:
		print('NO')


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
s = input()
t = input()
sa = [0] * (len(s) + 1)
sb = [0] * (len(s) + 1)
ta = [0] * (len(t) + 1)
tb = [0] * (len(t) + 1)
ca = 0
cb = 0
for (i, c) in enumerate(s):
	if c == 'A':
		ca += 1
	else:
		cb += 1
	sa[i + 1] = ca
	sb[i + 1] = cb
ca = 0
cb = 0
for (i, c) in enumerate(t):
	if c == 'A':
		ca += 1
	else:
		cb += 1
	ta[i + 1] = ca
	tb[i + 1] = cb
q = int(input())
for i in range(q):
	(a, b, c, d) = map(lambda x: int(x) - 1, input().split())
	if (sa[b + 1] - sa[a] - (sb[b + 1] - sb[a]) - (ta[d + 1] - ta[c] - (tb[d + 1] - tb[c]))) % 3 == 0:
		print('YES')
	else:
		print('NO')


S = input()
SA = [0]
n = 0
for c in S:
	if c == 'A':
		n += 1
	SA.append(n)
T = input()
TA = [0]
n = 0
for c in T:
	if c == 'A':
		n += 1
	TA.append(n)
q = int(input())
for _ in range(q):
	(a, b, c, d) = list(map(int, input().split()))
	nSA = SA[b] - SA[a - 1]
	nSB = b - a + 1 - nSA
	nTA = TA[d] - TA[c - 1]
	nTB = d - c + 1 - nTA
	print('YES' if (nSA - nSB) % 3 == (nTA - nTB) % 3 else 'NO')


ds = [0]
tmp = 0
for c in input():
	tmp += [-1, 1][c == 'A']
	ds.append(tmp)
dt = [0]
tmp = 0
for c in input():
	tmp += [-1, 1][c == 'A']
	dt.append(tmp)
q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	if abs(ds[b] - ds[a - 1] - (dt[d] - dt[c - 1])) % 3 == 0:
		print('YES')
	else:
		print('NO')


def I():
	return int(input())

def MI():
	return list(map(int, input().split()))

def LI():
	return list(map(int, input().split()))

def main():
	mod = 10 ** 9 + 7
	S = input()
	T = input()
	N = len(S)
	M = len(T)
	sa = [0] * (N + 1)
	for i in range(N):
		a = 0
		if S[i] == 'A':
			a = 1
		sa[i + 1] = sa[i] + a
	ta = [0] * (M + 1)
	for i in range(M):
		a = 0
		if T[i] == 'A':
			a = 1
		ta[i + 1] = ta[i] + a

	def f(a1, b1, a2, b2):
		a1 %= 3
		a2 = a2 % 3 + 3
		b1 %= 3
		b2 = b2 % 3 + 3
		da = a2 - a1
		db = b2 - b1
		return not (da - db) % 3

	def calc(a, b, c, d):
		a1 = sa[b] - sa[a - 1]
		b1 = b - a + 1 - a1
		a2 = ta[d] - ta[c - 1]
		b2 = d - c + 1 - a2
		return f(a1, b1, a2, b2)
	Q = I()
	for _ in range(Q):
		(a, b, c, d) = MI()
		if calc(a, b, c, d):
			print('YES')
		else:
			print('NO')
main()


S = input()
T = input()
accSA = [0] * (len(S) + 1)
accSB = [0] * (len(S) + 1)
for (i, s) in enumerate(S):
	accSA[i + 1] += accSA[i]
	accSB[i + 1] += accSB[i]
	if s == 'A':
		accSA[i + 1] += 1
	else:
		accSB[i + 1] += 1
accTA = [0] * (len(T) + 1)
accTB = [0] * (len(T) + 1)
for (i, s) in enumerate(T):
	accTA[i + 1] += accTA[i]
	accTB[i + 1] += accTB[i]
	if s == 'A':
		accTA[i + 1] += 1
	else:
		accTB[i + 1] += 1
Q = int(input())
ans = []
for _ in range(Q):
	(a, b, c, d) = map(int, input().split())
	sA = accSA[b] - accSA[a - 1]
	sB = accSB[b] - accSB[a - 1]
	tA = accTA[d] - accTA[c - 1]
	tB = accTB[d] - accTB[c - 1]
	sA = (sA + sB * 2) % 3
	tA = (tA + tB * 2) % 3
	ans.append('YES' if sA == tA else 'NO')
print(*ans, sep='\n')


def main():
	S = list(str(input()))
	T = list(str(input()))
	q = int(input())
	S_cum = [0]
	T_cum = [0]
	for i in S:
		if i == 'A':
			S_cum.append((S_cum[-1] + 1) % 3)
		else:
			S_cum.append((S_cum[-1] + 2) % 3)
	for i in T:
		if i == 'A':
			T_cum.append((T_cum[-1] + 1) % 3)
		else:
			T_cum.append((T_cum[-1] + 2) % 3)
	for i in range(q):
		(a, b, c, d) = map(int, input().split())
		s_ = S_cum[b] - S_cum[a - 1]
		t_ = T_cum[d] - T_cum[c - 1]
		if s_ % 3 == t_ % 3:
			print('YES')
		else:
			print('NO')
main()


S = input()
T = input()

def count(S):
	L = len(S)
	cA = [0] * (L + 1)
	cB = [0] * (L + 1)
	for i in range(L):
		cA[i + 1] = cA[i] + (S[i] == 'A')
		cB[i + 1] = cB[i] + (S[i] == 'B')
	return (cA, cB)
(sA, sB) = count(S)
(tA, tB) = count(T)
q = int(input())
ans = []
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	dA = sA[b] - sA[a - 1] - (tA[d] - tA[c - 1])
	dB = sB[b] - sB[a - 1] - (tB[d] - tB[c - 1])
	if (2 * dA + dB) % 3 == 0 and (dA + 2 * dB) % 3 == 0:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')