IN = open('abbaa.in').read().split()
out = open('abbaa.out', 'w').write
assert sum(len(s) for s in IN[1:]) <= 100000
for s in IN[1:]:
	for ch in s:
		assert ch in ['A', 'B']
	n = len(s)
	f = [None] * (n + 1)
	f[0] = True
	f[1] = s[0] == 'A'
	for i in range(2, n + 1):
		f[i] = (
			(f[i - 1] and (s[i - 1] == 'A')) 
			or (f[i - 2] and not (s[i - 2:i] == 'BB'))
		)
	out('YES\n' if f[n] else 'NO\n')
