Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:

he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);

or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent).

Therefore, each turn the length of the string is decreased exactly by $2$. All turns are independent so for each turn, Casimir can choose any of two possible actions.

For example, with $s$ $=$ "ABCABC" he can obtain a string $s$ $=$ "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.

For a given string $s$ determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Each test case is described by one string $s$, for which you need to determine if it can be fully erased by some sequence of turns. The string $s$ consists of capital letters 'A', 'B', 'C' and has a length from $1$ to $50$ letters, inclusive.


-----Output-----

Print $t$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).


-----Examples-----

Input
6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC
Output
NO
YES
NO
NO
YES
YES


-----Note-----

None

Difficulty: EASY
Tags: String algorithms

Mathematics

Starter code:

Solutions:
def solve(s):
	return s.count('B') == s.count('A') + s.count('C')
n = int(input())
for i in range(n):
	s = input()
	if solve(s):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	lst = [a + b + c]
	if len(set(s)) == 1:
		print('NO')
		continue
	if b == 0:
		print('NO')
		continue
	if b - a == c or b - c == a:
		print('YES')
	else:
		print('NO')


t = int(input())
L = []
for i in range(t):
	ch = input()
	nb1 = nb2 = 0
	for j in ch:
		if j == 'B':
			nb1 += 1
		else:
			nb2 += 1
	if nb1 == nb2:
		L.append('YES')
	else:
		L.append('NO')
for i in range(t):
	print(L[i])


def solution():
	for t in range(int(input())):
		s = input()
		l = len(s)
		if s.count('B') * 2 == l:
			print('YES')
		else:
			print('NO')
	return
solution()


for _ in range(int(input())):
	l = input()
	a = l.count('A')
	b = l.count('B')
	c = l.count('C')
	d = max(a, b, c)
	if d != b:
		print('no')
	elif b - (a + c) == 0:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	s = input()
	if s.count('B') == s.count('A') + s.count('C'):
		print('YES')
	else:
		print('NO')


inp = int(input())
res = []
for i in range(0, inp):
	x = input()
	if x.count('A') + x.count('C') == x.count('B'):
		res.append('YES')
	else:
		res.append('NO')
[print(x) for x in res]


t = int(input())
for i in range(t):
	string = input()
	string_length = len(string)
	num_b = string.count('B')
	print('YES') if num_b * 2 == string_length else print('NO')


n = int(input())
for _ in range(n):
	s = input()
	ac = bc = cc = 0
	for ele in s:
		if ele == 'A':
			ac += 1
		elif ele == 'B':
			bc += 1
		else:
			cc += 1
	if bc == ac + cc:
		print('YES')
	else:
		print('NO')


def check(s):
	(a, b, c) = (0, 0, 0)
	for i in s:
		if i == 'A':
			a += 1
		elif i == 'B':
			b += 1
		elif i == 'C':
			c += 1
	if a + c == b:
		print('YES')
	else:
		print('NO')
for t in range(int(input())):
	s = input()
	check(s)


for i in range(int(input())):
	s = input()
	num_a = s.count('A')
	num_b = s.count('B')
	num_c = s.count('C')
	if num_a + num_c == num_b:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
for i in range(t):
	s = input()
	c = Counter(s)
	x = c['A'] + c['C'] == c['B']
	print('YES' if x else 'NO')


t = int(input())
while t:
	s = input()
	if s.count('A') + s.count('C') == s.count('B'):
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
while t > 0:
	s = input()
	(ca, cb, cc) = (0, 0, 0)
	for i in s:
		if i == 'A':
			ca = ca + 1
		if i == 'B':
			cb = cb + 1
		if i == 'C':
			cc = cc + 1
	if cb == ca + cc:
		print('YES')
	else:
		print('NO')
	t = t - 1


for _ in range(int(input())):
	a = input()
	A = a.count('A')
	B = a.count('B')
	C = a.count('C')
	if A + C == B:
		print('YES')
	else:
		print('NO')


t = int(input())
A = []
for i in range(t):
	A.append(input())
for stroka in A:
	a = stroka.count('A')
	b = stroka.count('B')
	c = stroka.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from collections import Counter

def solve(s):
	count = Counter(s)
	a = count['A']
	b = count['B']
	c = count['C']
	return a + c == b
T = int(input())
for _ in range(T):
	s = input().strip()
	if solve(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	if s.count('A') + s.count('C') == s.count('B') and s.count('A') + s.count('B') + s.count('C') == len(s):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = input()
	p = len(l.split('A')) - 1
	r = len(l.split('C')) - 1
	q = len(l.split('B')) - 1
	if q == p + r:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	x = 0
	y = 0
	z = 0
	for i in range(len(s)):
		if s[i] == 'A':
			x = x + 1
		if s[i] == 'B':
			y = y + 1
		if s[i] == 'C':
			z = z + 1
	if x + z == y:
		print('YES')
	else:
		print('NO')


a = int(input())
for _ in range(a):
	n = input()
	a = n.count('A')
	b = n.count('B')
	c = n.count('C')
	if b == 0:
		print('NO')
		continue
	if a == 0 and c == b or (c == 0 and a == b):
		print('YES')
		continue
	if a > 0 and c > 0 and (a + c == b):
		print('YES')
		continue
	else:
		print('NO')
		continue


t = int(input())
for l in range(t):
	s = input()
	ch = s
	i = 0
	a = 0
	b = 0
	c = 0
	j = len(ch)
	for i in range(j):
		if ch[i] == 'A':
			a += 1
		elif ch[i] == 'B':
			b += 1
		elif ch[i] == 'C':
			c += 1
	if b < a:
		print('NO')
		continue
	b = b - a
	if b == c:
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	T -= 1
	ch = input()
	a = ch.count('A')
	b = ch.count('B')
	c = ch.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')


from collections import defaultdict as df
import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	s = input()
	cnt = df(int)
	for l in s:
		cnt[l] += 1
	a = cnt['A']
	b = cnt['B']
	c = cnt['C']
	if a + c != b:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a + c == b:
		print('YES')
	elif a == 0 and b == c or (c == 0 and a == b):
		print('YES')
	else:
		print('NO')
	t = t - 1


for _ in range(int(input())):
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a == c and 2 * a == b:
		print('YES')
	elif a + c == b:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	acnt = bcnt = ccnt = 0
	for c in input():
		if c == 'A':
			acnt += 1
		elif c == 'B':
			bcnt += 1
		elif c == 'C':
			ccnt += 1
	if acnt + ccnt == bcnt:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	(a, b, c) = (0, 0, 0)
	for l in s:
		if l == 'A':
			a += 1
		elif l == 'B':
			b += 1
		else:
			c += 1
	if a + c == b:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	if (s.count('A') + s.count('C')) * 2 == len(s):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = str(input())
	for i in range(int(len(s) / 2)):
		s = s.replace('AB', '')
		s = s.replace('BC', '')
		s = s.replace('CB', '')
		s = s.replace('BA', '')
	if len(s) == 0:
		print('YES')
	else:
		print('NO')


import sys
from math import ceil
from collections import defaultdict, Counter
TEST = 0
if TEST == 1:
	input_file = open('inputA.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))

def read_str_to_list():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return [x for x in in1]

def read_int_to_list():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return [int(x) for x in in1]
tests = read_int()
for test in range(tests):
	s = read_str_to_list()
	(countA, countB, countC) = (0, 0, 0)
	for c in s:
		if c is 'A':
			countA += 1
		elif c is 'B':
			countB += 1
		else:
			countC += 1
	if countB == countC + countA:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = input()
	a = n.count('A')
	b = n.count('B')
	c = n.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')


from collections import deque, Counter
from collections import defaultdict as dfd
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial, log2
from heapq import heapify, heappush, heappop
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

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

def stf():
	return file.readline().strip()

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

def readf():
	return list(map(int, file.readline().strip().split()))

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

def readffl():
	return list(map(float, file.readline().strip().split()))

def solve():
	for _ in range(nin()):
		s = st()
		dic = dfd(int)
		for i in s:
			dic[i] += 1
		if dic['B'] == dic['A'] + dic['C']:
			ans_.append('YES')
		else:
			ans_.append('NO')
solve()
for i in ans_:
	print(i)


for tc in range(int(input())):
	s = input()
	(count1, count2, count3) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'A':
			count1 += 1
		if s[i] == 'B':
			count2 += 1
		if s[i] == 'C':
			count3 += 1
	if count1 + count3 == count2:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	a = input()
	d = {}
	d['A'] = 0
	d['B'] = 0
	d['C'] = 0
	for k in a:
		d[k] += 1
	if d['A'] + d['C'] == d['B']:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	if len(s) % 2 == 0 and s.count('C') + s.count('A') == len(s) // 2:
		print('yes')
	else:
		print('no')


t = int(input())
while t > 0:
	t -= 1
	s = input()
	(m, n, k) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'A':
			m += 1
		elif s[i] == 'B':
			n += 1
		else:
			k += 1
	if n == m + k:
		print('YES')
	else:
		print('NO')


loop = int(input())
for idx in range(loop):
	str = input().upper()
	A = str.count('A')
	B = str.count('B')
	C = str.count('C')
	if A + C == B:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	x = input()
	if x.count('A') + x.count('C') == x.count('B'):
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())

def solve():
	s = input()
	c = Counter(s)
	c['B'] -= c['C']
	c['B'] -= c['A']
	if c['B'] == 0:
		print('YES')
	else:
		print('NO')
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	s = input()
	if s.count('A') + s.count('C') == s.count('B'):
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	s = input()
	ca = s.count('A')
	cb = s.count('B')
	cc = s.count('C')
	if cb - ca - cc == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	stroka = list(input())
	D = {'A': 0, 'B': 0, 'C': 0}
	for c in stroka:
		D[c] += 1
	if D['A'] + D['C'] == D['B']:
		print('YES')
	else:
		print('NO')


from collections import Counter
import sys, io, os
input = sys.stdin.readline

def solve():
	T = int(input())
	for _ in range(T):
		S = input().strip()
		c = Counter(S)
		if c['B'] > 0 and c['B'] == c['A'] + c['C']:
			print('YES')
		else:
			print('NO')
solve()


n = int(input())
for i in range(n):
	a = input()
	q1 = 0
	q2 = 0
	q3 = 0
	for e in range(len(a)):
		if a[e] == 'A':
			q1 += 1
		elif a[e] == 'B':
			q2 += 1
		elif a[e] == 'C':
			q3 += 1
	if q1 + q3 == q2:
		print('YES')
	else:
		print('NO')


b = 0
t = int(input())
for i in range(t):
	l = input()
	if l.count('B') == len(l) / 2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	l = list(input())
	a = l.count('A')
	b = l.count('B')
	c = l.count('C')
	if b == 0:
		print('NO')
	elif len(set(l)) == 3:
		if b == c + a:
			print('YES')
		else:
			print('NO')
	elif a == 0:
		if b == c:
			print('YES')
		else:
			print('NO')
	elif c == 0:
		if b == a:
			print('YES')
		else:
			print('NO')


try:
	for _ in range(int(input())):
		s = input()
		if s.count('B') == s.count('A') + s.count('C'):
			print('yes')
		else:
			print('no')
except:
	print('e')


from collections import Counter
for _ in range(int(input())):
	c = Counter(input())
	print('YES' if c['B'] - c['A'] == c['C'] else 'NO')


t = int(input())
for _ in range(t):
	s = input()
	ca = cb = cc = 0
	for i in s:
		if i == 'A':
			ca += 1
		elif i == 'B':
			cb += 1
		else:
			cc += 1
	if ca + cc == cb:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	count_a = s.count('A')
	count_b = s.count('B')
	count_c = s.count('C')
	if count_a + count_c == count_b:
		print('YES')
	else:
		print('NO')


n = int(input())
inputs = [input() for i in range(n)]
for i in inputs:
	if list(i).count('A') + list(i).count('C') == list(i).count('B'):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	S = input()
	Hm = {'A': 0, 'B': 0, 'C': 0}
	for i in S:
		Hm[i] += 1
	a = Hm['A']
	b = Hm['B']
	c = Hm['C']
	b -= a
	if b == c:
		print('YES')
	else:
		print('NO')


n = int(input())
a = []
x = 0
b = 0
c = 0
for i in range(n):
	a.append(input())
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 'B':
			b += 1
		elif a[i][j] == 'C':
			c += 1
		elif a[i][j] == 'A':
			x += 1
	if x + c == b:
		print('YES')
	else:
		print('NO')
	x = 0
	b = 0
	c = 0


n = int(input())
while n != 0:
	s = input()
	if s.count('B') == s.count('A') + s.count('C'):
		print('Yes')
	else:
		print('No')
	n = n - 1


n = int(input())
s = []
for i in range(n):
	a_k = 0
	b_k = 0
	c_k = 0
	a = input()
	for j in range(len(a)):
		if a[j] == 'A':
			a_k += 1
		if a[j] == 'B':
			b_k += 1
		if a[j] == 'C':
			c_k += 1
	if a_k > b_k:
		s.append('NO')
	else:
		b_k -= a_k
		if b_k == c_k:
			s.append('YES')
		else:
			s.append('NO')
for k in range(len(s)):
	print(s[k])


x = int(input())
while True:
	p = input()
	q = 0
	r = 0
	for j in p:
		if j == 'C' or j == 'A':
			q = q + 1
		else:
			r = r + 1
	if q == r:
		print('YES')
	else:
		print('NO')
	x = x - 1
	if x > 0:
		continue
	else:
		break


for s in [*open(0)][1:]:
	c = s.count
	print('YNEOS'[c('A') + c('C') != c('B')::2])


def split(n):
	return [char for char in n]
for _ in range(int(input())):
	n = input()
	n = split(n)
	a = n.count('A')
	b = n.count('B')
	c = n.count('C')
	if a == b and c == 0 or (b == c and a == 0) or (a < b and b - a - c == 0):
		print('YES')
	else:
		print('NO')


def print_hi(st):
	aa = 0
	bb = 0
	cc = 0
	for j in range(len(st)):
		if st[j] == 'A':
			aa += 1
		elif st[j] == 'B':
			bb += 1
		elif st[j] == 'C':
			cc += 1
	if len(st) % 2 != 0:
		print('NO')
	elif bb == aa + cc:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	st = input()
	print_hi(st)


t = int(input())
for i in range(0, t):
	str = input()
	x = len(str)
	a = str.count('A')
	b = str.count('B')
	c = str.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	a = b = c = 0
	for i in input().strip():
		if i == 'A':
			a += 1
		elif i == 'B':
			b += 1
		else:
			c += 1
	if b == a + c:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	if n % 2 == 0:
		b = s.count('B')
		a = s.count('A')
		c = s.count('C')
		if b != n // 2:
			print('NO')
		elif a == n // 2 or c == n // 2 or a + c == n // 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


inp1 = int(input())
for i in range(inp1):
	inp2 = input()
	if inp2.count('A') + inp2.count('C') == inp2.count('B'):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	x = input()
	val = 0
	if len(x) % 2 == 0:
		if x.count('B') == len(x) / 2:
			val = 1
	if val == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	Soli = list(input())
	A = Soli.count('A')
	B = Soli.count('B')
	C = Soli.count('C')
	if A + C == B:
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	s = input()
	A = 0
	B = 0
	C = 0
	for i in s:
		if i == 'A':
			A += 1
		elif i == 'B':
			B += 1
		else:
			C += 1
	if A + C == B:
		print('YES')
	else:
		print('NO')
	t -= 1


for t in range(int(input())):
	s = input()
	n = len(s)
	cnta = s.count('A')
	cntb = s.count('B')
	cntc = s.count('C')
	if cntb == n // 2 and cnta + cntc == n // 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	ip = input()
	ip = list(ip)
	while 'A' in ip and 'B' in ip or ('B' in ip and 'C' in ip):
		if 'A' in ip and 'B' in ip:
			ip.remove('B')
			ip.remove('A')
		elif 'B' in ip and 'C' in ip:
			ip.remove('B')
			ip.remove('C')
	if len(ip) == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	str = input()
	a = str.count('A')
	b = str.count('B')
	c = str.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')
	t = t - 1


def check(val):
	x = val.count('A')
	y = val.count('B')
	z = val.count('C')
	if x - y > 0:
		print('NO')
	elif z - y > 0:
		print('NO')
	elif x - y < 0 and z + (x - y) == 0:
		print('YES')
	elif z - y < 0 and x + (z - y) == 0:
		print('YES')
	elif x - y == 0 and z > 0:
		print('NO')
	elif z - y == 0 and x > 0:
		print('NO')
	elif x - y == 0 and z == 0 or (z - y == 0 and x == 0):
		print('YES')
	elif x + y != z:
		print('NO')
trials = int(input())
li = []
for i in range(0, trials):
	temp = input()
	li.append(temp)
for l in li:
	check(l)


numberTestCases = int(input())
cases = []
output = []
for i in range(numberTestCases):
	cases.append(input())
for case in cases:
	numA = case.count('A')
	numB = case.count('B')
	numC = case.count('C')
	if numA + numC == numB:
		output.append('YES')
	else:
		output.append('NO')
for out in output:
	print(out)


tc = int(input())
while tc != 0:
	arr = input()
	size = len(arr)
	if size % 2 != 0:
		print('NO')
	else:
		i = 0
		counta = 0
		countb = 0
		while i < size:
			if arr[i] == 'A' or arr[i] == 'C':
				counta += 1
			if arr[i] == 'B':
				countb += 1
			i += 1
		if counta == countb:
			print('YES')
		else:
			print('NO')
	tc -= 1


for _ in range(int(input())):
	l = [i for i in input()]
	if len(l) % 2 == 1:
		print('NO')
	elif l.count('B') == l.count('A') + l.count('C'):
		print('YES')
	else:
		print('NO')


def main(string):
	if len(set(string)) == 1:
		return 'NO'
	elif 'B' not in string:
		return 'NO'
	elif 'A' not in string:
		if string.count('B') == string.count('C'):
			return 'YES'
		return 'NO'
	elif 'C' not in string:
		if string.count('B') == string.count('A'):
			return 'YES'
		return 'NO'
	else:
		if string.count('B') == string.count('A') + string.count('C'):
			return 'YES'
		return 'NO'
for _ in range(int(input())):
	print(main(input()))


def func(n):
	for _ in range(n):
		a = input()
		if a.count('B') == len(a) / 2:
			k.append('YES')
		else:
			k.append('NO')
	print('\n'.join(k))
k = []
func(int(input()))


for _ in range(int(input())):
	s = input()
	n_A = s.count('A')
	n_B = s.count('B')
	n_C = s.count('C')
	if n_A + n_C == n_B:
		print('yes')
	else:
		print('no')


n = int(input())
for _ in range(n):
	s = input()
	i = 0
	(r, p) = (0, 0)
	for i in s:
		if i == 'A' or i == 'C':
			r += 1
		elif i == 'B':
			p += 1
	if r == p:
		print('YES')
	else:
		print('NO')


test_cases = input()
string_array = []
for i in range(int(test_cases)):
	string_array.append(input())
for string in string_array:
	sum_dict = {'A': 0, 'B': 0, 'C': 0}
	for i in string:
		sum_dict[i] += 1
	if sum_dict['A'] + sum_dict['C'] == sum_dict['B']:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = ''.join(sorted(input()))
	while 'AB' in s or 'BA' in s:
		s = s.replace('AB', '').replace('BA', '')
	while 'BC' in s or 'CB' in s:
		s = s.replace('BC', '').replace('CB', '')
	if len(s) == 0:
		print('YES')
	else:
		print('NO')


import sys

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

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

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

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

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		s = get_string()
		(a, b, c) = (0, 0, 0)
		for i in range(len(s)):
			if s[i] == 'A':
				a += 1
			elif s[i] == 'B':
				b += 1
			else:
				c += 1
		if a == 0:
			if b == 0 or c == 0:
				get_print('NO')
			elif b == c:
				get_print('YES')
			else:
				get_print('NO')
		elif b == 0:
			get_print('NO')
		elif c == 0:
			if b == 0 or a == 0:
				get_print('NO')
			elif b == a:
				get_print('YES')
			else:
				get_print('NO')
		elif b == a + c:
			get_print('YES')
		else:
			get_print('NO')
solve()


for _t in range(int(input())):
	s = input()
	if 2 * s.count('B') == len(s):
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	s = input()
	(countA, countB, countC) = (0, 0, 0)
	res = ''
	for i in s:
		if i == 'A':
			countA += 1
		elif i == 'B':
			countB += 1
		else:
			countC += 1
	if countB == countA + countC:
		res = 'YES'
	else:
		res = 'NO'
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	d = {'A': 0, 'B': 0, 'C': 0}
	for i in s:
		d[i] += 1
	if d['B'] == d['A'] + d['C']:
		print('YES')
	else:
		print('NO')


import sys
from collections import Counter
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	s = Counter(input())
	if s['A'] + s['C'] == s['B']:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = len(s) - a - b
	print('YES' if a + c == b else 'NO')


for i in range(int(input())):
	s = str(input())
	ans = ''
	count = len(s)
	l = list(s)
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a + c == b:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	s = input()
	n = len(s)
	c = 0
	b = 0
	a = 0
	if n < 2:
		print('NO')
	else:
		for i in range(n):
			if s[i] == 'A':
				a += 1
			elif s[i] == 'B':
				b += 1
			else:
				c += 1
		if a + c == b:
			print('YES')
		else:
			print('NO')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07

def hnbhai(tc):
	s = sa()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a + c == b:
		print('YES')
		return
	print('NO')
for _ in range(sb()):
	hnbhai(_ + 1)


for i in range(int(input())):
	ch = input()
	if 2 * ch.count('B') == len(ch):
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	b = input()
	d = b.count('A')
	e = b.count('B')
	f = b.count('C')
	if e - f - d == 0:
		print('YES')
	else:
		print('No')


import sys
readline = sys.stdin.readline
T = int(readline())
for _ in range(T):
	S = readline().rstrip()
	(A, B, C) = (0, 0, 0)
	for s in S:
		if s == 'A':
			A += 1
		elif s == 'B':
			B += 1
		else:
			C += 1
	if A + C == B:
		ans = 'YES'
	else:
		ans = 'NO'
	print(ans)


T = int(input())
for i in range(T):
	s = input()
	a = []
	a[:0] = s
	if a.count('A') + a.count('C') == a.count('B'):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def get():
	return input().strip()
for _ in range(int(get())):
	l = list(get())
	a = len(l)
	c = 0
	while True:
		f = 0
		if 'A' in l and 'B' in l and (c < 2):
			l.remove('A')
			l.remove('B')
			f = 1
		if 'C' in l and 'B' in l and (c < 2):
			l.remove('C')
			l.remove('B')
			f = 1
		if f == 0:
			break
	if len(l) == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = input()
	ac = bc = cc = 0
	for i in a:
		if i == 'A':
			ac += 1
		elif i == 'B':
			bc += 1
		elif i == 'C':
			cc += 1
	if ac + cc == bc:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	a = 0
	b = 0
	c = 0
	inpt = input()
	for j in inpt:
		if j == 'A':
			a = a + 1
		elif j == 'B':
			b = b + 1
		else:
			c = c + 1
	if len(inpt) % 2 == 0 and len(inpt) / 2 == b:
		if a == b or c == b or a + c == b:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def prob1():
	t = int(input())
	for i in range(t):
		s = input('')
		nummap = {'A': 0, 'B': 0, 'C': 0}
		for j in range(len(s)):
			nummap[s[j]] += 1
		nummap['B'] = nummap['B'] - nummap['A'] - nummap['C']
		if nummap['B'] == 0:
			print('YES')
		else:
			print('NO')
prob1()


for i in range(int(input())):
	x = list(input())
	if x.count('B') == len(x) / 2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	count = s.count('B')
	remlen = len(s) - count * 2
	if remlen == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
for j in range(n):
	s = input()
	ca = 0
	cb = 0
	cc = 0
	for i in s:
		if i == 'A':
			ca += 1
		elif i == 'B':
			cb += 1
		else:
			cc += 1
	print('YES' if cb == ca + cc else 'NO')


t = int(input())
for i in range(t):
	s = str(input())
	A = 0
	B = 0
	C = 0
	if len(s) % 2 == 1:
		print('NO')
	else:
		for j in range(len(s)):
			if s[j] == 'B':
				B += 1
			elif s[j] == 'A':
				A += 1
			elif s[j] == 'C':
				C += 1
		if B == A + C:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	s = input()
	b = s.count('B')
	if len(s) - b == b:
		print('YES')
	else:
		print('NO')


def sol(s):
	d = {'A': 0, 'B': 0, 'C': 0}
	for si in s:
		d[si] += 1
	total = len(s)
	if d['A'] * 2 + d['C'] * 2 == total:
		if d['A'] + d['C'] == d['B']:
			return 'YES'
	return 'NO'
t = int(input())
ans = []
for i in range(t):
	temp = input()
	ans.append(sol(temp))
for i in ans:
	print(i)


n = int(input())
for i in range(n):
	s = [i for i in input()]
	while s.count('B') != 0 and s.count('C') != 0:
		s.remove('B')
		s.remove('C')
	while s.count('A') != 0 and s.count('B') != 0:
		s.remove('A')
		s.remove('B')
	if len(s) == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
ans = []
for _ in range(t):
	s = list(input())
	while 'A' in s and 'B' in s or ('B' in s and 'C' in s):
		if 'A' in s and 'B' in s:
			s.remove('A')
			s.remove('B')
		if 'B' in s and 'C' in s:
			s.remove('B')
			s.remove('C')
	ans.append(s)
for i in ans:
	print('NYOE S'[len(i) == 0::2])


for s in [*open(0)][1:]:
	print('YNEOS'[2 * s.count('B') != len(s) - 1::2])


def solve():
	string = input()
	(a, b, c) = (0, 0, 0)
	for i in string:
		if i == 'A':
			a += 1
		elif i == 'B':
			b += 1
		else:
			c += 1
	if a + c == b:
		return 'YES'
	return 'NO'
t = int(input())
while t != 0:
	res = solve()
	print(res)
	t -= 1


import os, sys, math
from io import BytesIO, IOBase
ip = lambda : input()
it = lambda : int(input())
ma = lambda : map(int, input().split(' '))
li = lambda : list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
md = 998244353

def solve(a, n, x):
	return a

def main():
	for _ in range(int(input())):
		s = ip()
		l = len(s)
		a = s.count('A')
		b = s.count('B')
		c = l - a - b
		if b == a + c:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def test():
	t = int(input())
	for _ in range(t):
		d = [0, 0, 0]
		s = input()
		for c in s:
			if c == 'A':
				d[0] += 1
			elif c == 'B':
				d[1] += 1
			else:
				d[2] += 1
		if d[0] + d[2] == d[1]:
			print('YES')
		else:
			print('NO')
test()


n = int(input())
for i in range(n):
	a = input()
	c = 0
	if a == 'AB' or a == 'BC' or a == 'CB' or (a == 'BA'):
		print('YES')
	elif len(a) % 2 != 0 or len(a) <= 2:
		print('NO')
	else:
		for P in a:
			if P == 'B':
				c = c + 1
		if c == len(a) // 2:
			print('YES')
		else:
			print('NO')


count = int(input())
for i in range(count):
	string = input()
	(a, b, c) = (0, 0, 0)
	for char in string:
		if char == 'A':
			a += 1
		if char == 'B':
			b += 1
		if char == 'C':
			c += 1
	if a + c == b:
		print('yes')
	else:
		print('no')


num = int(input())
ar = []
for i in range(num):
	ar.append(input())
for i in range(num):
	if ar[i].count('B') == len(ar[i]) / 2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	a = b = 0
	for i in s:
		if i == 'A' or i == 'C':
			a += 1
		else:
			b += 1
	print('YES' if a == b else 'NO')


t = int(input())
while t > 0:
	s = input()
	cnt1 = 0
	cnt2 = 0
	cnt3 = 0
	for i in range(0, len(s)):
		if s[i] == 'B':
			cnt1 += 1
	if len(s) == 2 * cnt1:
		print('YES')
	else:
		print('NO')
	t -= 1


hm = int(input())
for _ in range(hm):
	inp = list(input())
	ac = inp.count('A') + inp.count('C')
	b = inp.count('B')
	if ac - b == 0:
		print('YES')
	else:
		print('NO')


import math as m
x = int(input())
y = [str(input()) for i in range(x)]

def f(s, z):
	return len(s) - len(s.replace(z, ''))
for i in range(len(y)):
	if f(y[i], 'A') + f(y[i], 'B') == f(y[i], 'C') and f(y[i], 'A') == f(y[i], 'B') and (f(y[i], 'A') != 1) or (f(y[i], 'A') + f(y[i], 'B') == f(y[i], 'C') and f(y[i], 'B') == f(y[i], 'C')):
		print('YES')
	elif f(y[i], 'B') + f(y[i], 'C') == f(y[i], 'A') and f(y[i], 'B') == f(y[i], 'C') and (f(y[i], 'B') != 1) or (f(y[i], 'B') + f(y[i], 'C') == f(y[i], 'A') and f(y[i], 'B') == f(y[i], 'A')):
		print('YES')
	elif f(y[i], 'C') + f(y[i], 'A') == f(y[i], 'B') and f(y[i], 'C') == f(y[i], 'A') and (f(y[i], 'C') != 1) or (f(y[i], 'C') + f(y[i], 'A') == f(y[i], 'B') and f(y[i], 'C') == f(y[i], 'B')) or (f(y[i], 'C') + f(y[i], 'A') == f(y[i], 'B') and f(y[i], 'A') == f(y[i], 'B')):
		print('YES')
	elif f(y[i], 'C') + f(y[i], 'A') == f(y[i], 'B'):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	w = s.count('A') + s.count('C')
	if w == s.count('B'):
		print('YES')
	else:
		print('NO')


i = int(input())
for j in range(i):
	s = input()
	count = 0
	for i in s:
		if i == 'A':
			count += 1
		elif i == 'B':
			count -= 1
		elif i == 'C':
			count += 1
	if count == 0:
		print('YES')
	else:
		print('NO')


def main():

	def solve(s):
		ac = b = 0
		for c in s:
			if c == 'B':
				b += 1
			else:
				ac += 1
		return 'YES' if ac == b else 'NO'
	t = int(input())
	for _ in range(t):
		s = input().strip()
		print(solve(s))
import sys, threading
input = sys.stdin.readline
thread = threading.Thread(target=main)
thread.start()
thread.join()


i = int(input())
m = []
n = []
for j in range(i):
	m.append(input())
for j in range(i):
	Acount = 0
	Bcount = 0
	for x in m[j]:
		if x == 'A' or x == 'C':
			Acount += 1
		if x == 'B':
			Bcount += 1
	if Acount == Bcount:
		n.append('yes')
	else:
		n.append('no')
for j in range(i):
	print(n[j])


t = int(input())

def func(s):
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a + c != b:
		return 'NO'
	return 'YES'
for i in range(t):
	s = input()
	print(func(s))


from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())
ro = lambda : int(input())

def solve():
	s = input()
	n = len(s)
	if n & 1:
		print('NO')
		return
	cnt = defaultdict(int)
	for c in s:
		cnt[c] += 1
	(a, b, c) = ('A', 'B', 'C')
	if cnt[b] < cnt[a]:
		print('NO')
		return
	cnt[b] -= cnt[a]
	if cnt[b] < cnt[c]:
		print('NO')
		return
	cnt[b] -= cnt[c]
	if cnt[b] == 0:
		print('YES')
	else:
		print('NO')
t = 1
t = int(input())
while t:
	t -= 1
	solve()


t = int(input())
for _ in range(t):
	s = input()
	if len(s) & 1 or s.count('B') != len(s) // 2:
		print('NO')
	else:
		print('YES')


def solution(string):
	counter = {'A': 0, 'B': 0, 'C': 0}
	for character in string:
		counter[character] += 1
	return counter['A'] + counter['C'] == counter['B']

def main():
	n = int(input())
	for _ in range(n):
		string = input()
		if solution(string):
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for _ in range(t):
	s = input()
	cnt = 0
	for e in s:
		if e == 'B':
			cnt += 1
	print(['NO', 'YES'][cnt == len(s) - cnt])


import sys

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

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

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

def get_int():
	return int(sys.stdin.readline().strip())

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

def solve(s):
	a = 0
	b = 0
	c = 0
	for ele in s:
		if ele == 'A':
			a += 1
		elif ele == 'B':
			b += 1
		else:
			c += 1
	if a + c != b:
		print('NO')
	else:
		print('YES')
T = get_int()
while T:
	s = get_string()
	solve(s)
	T -= 1


a = int(input())
for i in range(a):
	b = input()
	if b.count('A') + b.count('C') == b.count('B'):
		print('YES')
	else:
		print('NO')


santhosh = int(input())
for _ in range(santhosh):
	sandy = input()
	bcounting_varible = sandy.count('B')
	ccounting_varibles = sandy.count('C')
	acounting_varible = sandy.count('A')
	if acounting_varible + ccounting_varibles == bcounting_varible:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	b = str(input())
	countA = b.count('A')
	countB = b.count('B')
	countC = b.count('C')
	result = countB - (countA + countC)
	if result == 0:
		print('YES')
	else:
		print('NO')


(a, d) = (int(input()), [])
for i in range(0, a):
	b = input()
	if len(b) % 2 == 1:
		d.append('NO')
	elif b.count('A') + b.count('C') == b.count('B'):
		d.append('YES')
	else:
		d.append('NO')
print(*d, sep='\n')


t = int(input())

def rem(lis, it):
	for i in lis:
		lis.remove(i)
	return lis

def count(res):
	a = 0
	b = 0
	c = 0
	for i in range(len(res)):
		if res[i] == 'A':
			a = a + 1
		if res[i] == 'B':
			b = b + 1
		if res[i] == 'C':
			c = c + 1
	return (a, b, c)
while t > 0:
	test = input()
	res = list(test)
	cc = count(res)
	a = cc[0]
	b = cc[1]
	c = cc[2]
	if b == a + c:
		print('YES')
	else:
		print('NO')
	t = t - 1


from sys import stdin
from io import StringIO
input = lambda : stdin.readline().strip()
linput = lambda : [*map(int, input().split())]

def main():
	s = input()
	if s.count('B') == s.count('A') + s.count('C'):
		print('YES')
	else:
		print('NO')
for _ in ' ' * int(input()):
	main()


from collections import defaultdict
m = int(input())
ans = []
for _ in range(m):
	d = defaultdict(int)
	s = str(input())
	for i in s:
		d[i] += 1
	ans.append('YES' if d['A'] + d['C'] == d['B'] else 'NO')
for i in ans:
	print(i)


n = int(input())
s = list()
for i in range(n):
	s.append(input())
l = list()
for j in s:
	ca = 0
	cb = 0
	cc = 0
	l.clear()
	l = list(j)
	for k in l:
		if k == 'A':
			ca += 1
		elif k == 'B':
			cb += 1
		else:
			cc += 1
	cn = cc + ca
	if cn == cb:
		print('YES')
	else:
		print('NO')


num = int(input())
cases = [input() for _ in range(num)]
for _str in cases:
	print('YES' if _str.count('B') == _str.count('A') + _str.count('C') else 'NO')


t = int(input())
for i in range(t):
	s = input()
	if len(s) % 2 != 0:
		print('NO')
		continue
	d = dict()
	for i in s:
		d[i] = d.get(i, 0) + 1
	if 'C' not in d.keys():
		d['C'] = 0
	if 'B' not in d.keys():
		d['B'] = 0
	if 'A' not in d.keys():
		d['A'] = 0
	if d['A'] + d['C'] == d['B']:
		print('YES')
	else:
		print('NO')


from collections import Counter

def main():
	s = input()
	c = Counter(s)
	if c['A'] + c['C'] == c['B']:
		print('YES')
	else:
		print('NO')
t = int(input())
while t > 0:
	t -= 1
	main()


from sys import stdin, stdout

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

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

def solve():
	s = SI()
	l = len(s)
	if l == 0:
		stdout.write('YES\n')
		return
	(a, b, c) = (0, 0, 0)
	for x in s:
		if x == 'A':
			a += 1
		elif x == 'B':
			b += 1
		elif x == 'C':
			c += 1
	l = b - a - c
	if l == 0:
		stdout.write('YES\n')
	else:
		stdout.write('NO\n')
t = II()
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	a = input()
	n = len(a)
	A = a.count('A')
	B = a.count('B')
	C = a.count('C')
	if B == A + C:
		print('YES')
	else:
		print('NO')


NUM = int(input())
ans = []
for _ in range(NUM):
	line = input()
	(a, b, c) = (line.count('A'), line.count('B'), line.count('C'))
	if b == a + c:
		ans.append('Yes')
	else:
		ans.append('No')
for i in ans:
	print(i)


t = int(input())
while t:
	t -= 1
	s = input()
	a = s.count('B')
	if a == len(s) // 2 and len(s) % 2 == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = list(input())
	acount = s.count('A')
	bcount = s.count('B')
	ccount = s.count('C')
	length = len(s)
	ab_min = min(acount, bcount)
	length = length - 2 * ab_min
	acount = acount - ab_min
	bcount = bcount - ab_min
	length = length - 2 * min(bcount, ccount)
	if length == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	count_a = 0
	count_b = 0
	count_c = 0
	for j in range(len(s)):
		if s[j] == 'A':
			count_a += 1
		elif s[j] == 'B':
			count_b += 1
		else:
			count_c += 1
	if count_b == count_c + count_a:
		print('YES')
	else:
		print('NO')


count = int(input())
for i in range(0, count):
	string = input()
	aCount = string.count('A')
	bCount = string.count('B')
	cCount = string.count('C')
	acCount = aCount + cCount
	if len(string) % 2 != 0:
		print('NO')
	elif acCount == bCount:
		print('YES')
	else:
		print('NO')


for _ in range(int(input().strip())):
	s = input().strip()
	b_count = s.count('B')
	a_count = s.count('A')
	c_count = s.count('C')
	if b_count == a_count + c_count:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	s = input()
	if s.count('B') == len(s) / 2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = input()
	a = 0
	b = 0
	c = 0
	for x in range(len(n)):
		if n[x] == 'A':
			a += 1
		elif n[x] == 'B':
			b += 1
		elif n[x] == 'C':
			c += 1
	if b == a + c:
		print('yes')
	else:
		print('no')


n = int(input())
while n:
	s = input()
	count = 0
	k = len(s)
	for i in range(k):
		if s[i] == 'B':
			count += 1
	if k % 2 == 0 and count == k / 2:
		print('YES')
	else:
		print('NO')
	n -= 1


import sys
input = sys.stdin.readline

def get_integers():
	return map(int, input().strip().split())

def solve(s: str):
	storage = [0] * 3
	for char in s:
		if char == 'A':
			storage[0] += 1
		elif char == 'B':
			storage[1] += 1
		elif char == 'C':
			storage[2] += 1
	if storage[0] + storage[2] == storage[1]:
		return 'YES'
	return 'NO'
t = int(input().strip())
for _ in range(t):
	s = input().strip()
	ans = solve(s)
	print(ans)


x = int(input())
for i in range(x):
	st = input()
	l = len(st)
	c = st.count('B')
	if c * 2 == l:
		print('Yes')
	else:
		print('No')


import sys
import math
from bisect import bisect_right as br
from itertools import combinations as cb

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	st = input()
	a = 0
	b = 0
	c = 0
	for i in st:
		if i == 'A':
			a += 1
		elif i == 'B':
			b += 1
		else:
			c += 1
	if c > b:
		print('NO')
		continue
	b -= c
	if a != b:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	(a, b, c) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'A':
			a += 1
		if s[i] == 'B':
			b += 1
		if s[i] == 'C':
			c += 1
	if a + c == b:
		print('YES')
	else:
		print('NO')


def casimir(N):
	b = 0
	for i in N:
		if i == 'B':
			b += 1
	a = float(len(N) / 2)
	if a == b:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	A = str(input())
	casimir(A)


a = input()
while True:
	try:
		cin = input()
		ca = 0
		cb = 0
		cc = 0
		for i in cin:
			if i == 'A':
				ca += 1
			if i == 'B':
				cb += 1
			if i == 'C':
				cc += 1
		if ca == cb - cc:
			print('YES')
		else:
			print('NO')
	except:
		break


n = int(input())
for _ in range(n):
	l = list(input())
	count_A = len([i for i in l if i == 'A'])
	count_B = len([i for i in l if i == 'B'])
	count_C = len([i for i in l if i == 'C'])
	if count_C + count_A == count_B or l in ['AB', 'BC', 'BA', 'CB']:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	b = 0
	n = len(s)
	for item in s:
		if item == 'B':
			b += 1
	if n % 2 != 0:
		print('NO')
	elif b == int(n / 2):
		print('YES')
	else:
		print('NO')


times = int(input())
for i in range(times):
	question = input()
	now = [question.count('A'), question.count('B'), question.count('C')]
	if now[1] == now[0] + now[2]:
		print('YES')
	else:
		print('NO')


t = eval(input())
for i in range(t):
	sum1 = sum2 = sum3 = 0
	a = input()
	for j in a:
		if j == 'A':
			sum1 = sum1 + 1
		elif j == 'B':
			sum2 = sum2 + 1
		else:
			sum3 = sum3 + 1
	if sum1 + sum3 == sum2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	if len(s) % 2 == 0:
		while 'A' in s and 'B' in s:
			s = s.replace('A', '', 1)
			s = s.replace('B', '', 1)
		while 'B' in s and 'C' in s:
			s = s.replace('B', '', 1)
			s = s.replace('C', '', 1)
		if s:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


import math
import sys
import collections
import bisect
import time
import random
import itertools
import string
from collections import Counter, defaultdict

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	s = list(get_string())
	(a, b, c) = (s.count('A'), s.count('B'), s.count('C'))
	if b >= a and b - a == c:
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	t -= 1
	s = input()
	if len(s) % 2 != 0:
		print('NO')
	else:
		a = s.count('A')
		b = s.count('B')
		c = s.count('C')
		if b == a + c:
			print('YES')
		else:
			print('NO')


from bisect import bisect_left as bl
n = int(input())
for i in range(n):
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')


n = int(input())
words = [0] * n
for i in range(n):
	words[i] = input()
	word = words[i]
	aCounter = 0
	bCounter = 0
	cCounter = 0
	counter = 0
	for j in range(len(word)):
		if word[j] == 'A':
			aCounter += 1
			counter += 1
		elif word[j] == 'B':
			bCounter += 1
			counter += 1
		elif word[j] == 'C':
			cCounter += 1
			counter += 1
	if aCounter == bCounter - cCounter:
		print('Yes')
	else:
		print('NO')


def f(s: list):
	if len(s) < 2:
		return 'no'
	ca = s.count('A')
	i = 0
	while i < ca:
		s.remove('A')
		if 'B' in s:
			s.remove('B')
		else:
			return 'no'
		i += 1
	i = 0
	cb = s.count('B')
	while i < cb:
		s.remove('B')
		if 'C' in s:
			s.remove('C')
		else:
			return 'no'
		i += 1
	if s:
		return 'no'
	else:
		return 'yes'
t = int(input())
for i in range(t):
	s = list(input())
	print(f(s).upper())


t = int(input())
while t:
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	min_ab = min(a, b)
	min_bc = min(b, c)
	if min_ab > -1:
		a = a - min_ab
		b = b - min_ab
	if min_bc > -1:
		b = b - min_bc
		c = c - min_bc
	if a == b == c:
		print('YES')
	else:
		print('NO')
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().rstrip()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if a + c == b:
		print('YES')
	else:
		print('NO')


from collections import Counter

def main():
	t = int(input())
	for i in range(t):
		s = input()
		ocurrences = Counter(s)
		if ocurrences['B'] == ocurrences['A'] + ocurrences['C']:
			print('YES')
		else:
			print('NO')
main()


from collections import Counter
for _ in range(int(input())):
	s = input()
	d = Counter(s)
	if d.get('B') == None:
		print('NO')
	else:
		a = c = 0
		if d.get('A') != None:
			a = d['A']
		if d.get('C') != None:
			c = d['C']
		if a + c == d['B']:
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(0, n):
	l = list(map(str, input()))
	while 'A' in l and 'B' in l:
		l.remove('A')
		l.remove('B')
	while 'C' in l and 'B' in l:
		l.remove('C')
		l.remove('B')
	if len(l) == 0:
		print('YES')
	else:
		print('NO')


def cst(s):
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if len(s) == 0:
		return True
	if c == 0:
		return a == b
	elif a == 0:
		return b == c
	elif b == 0:
		return False
	return a + c == b
for _ in range(int(input())):
	flg = cst(str(input()))
	if flg:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = str(input())
	b = a.count('A')
	c = a.count('B')
	d = a.count('C')
	if len(a) % 2 == 0 and b + d == c:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = input()
	(s_a_c, s_b) = (0, 0)
	for el in l:
		if el in ['A', 'C']:
			s_a_c += 1
		else:
			s_b += 1
	if s_a_c == s_b:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	n = input()
	k = len(n)
	ao = 0
	bo = 0
	co = 0
	for i in range(k):
		if n[i] == 'A':
			ao = ao + 1
		elif n[i] == 'B':
			bo = bo + 1
		elif n[i] == 'C':
			co = co + 1
	if ao + co == bo:
		print('YES')
	else:
		print('NO')
	t = t - 1


import math
from collections import defaultdict, Counter
for t in range(int(input())):
	s = input()
	d = Counter(s)
	if d['C'] + d['A'] == d['B']:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	str1 = input()
	count_a = str1.count('A')
	count_b = str1.count('B')
	count_c = str1.count('C')
	if len(str1) % 2 != 0:
		print('NO')
	elif count_a + count_c == count_b:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	n = input()
	res = list(n)
	res = sorted(res)
	ca = res.count('A')
	cb = res.count('B')
	cc = res.count('C')
	if ca > cb:
		print('NO')
	elif ca <= cb:
		x = cb - ca
		if x == cc:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t = t - 1


t = int(input())
for i in range(0, t):
	s = input()
	v = 0
	c1 = s.count('A')
	c2 = s.count('B')
	c3 = s.count('C')
	if c2 > c1 + c3:
		v += 2 * (c1 + c3)
	elif c2 <= c1 + c3:
		v += 2 * c2
	if len(s) - v == 0:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	a = input()
	ac = 0
	bc = 0
	cc = 0
	for j in range(len(a)):
		if a[j] == 'A':
			ac = ac + 1
		if a[j] == 'B':
			bc = bc + 1
		if a[j] == 'C':
			cc = cc + 1
	if bc == ac + cc:
		print('YES')
	else:
		print('NO')


def myfunction():
	length = int(input(''))
	for i in range(length):
		string = input('')
		a = 0
		b = 0
		c = 0
		for i in range(len(string)):
			if string[i] == 'A':
				a += 1
			elif string[i] == 'B':
				b += 1
			else:
				c += 1
		if b == a + c:
			print('YES')
		else:
			print('No')
myfunction()


t = int(input())
while t > 0:
	n = input()
	d = {'A': 0, 'B': 0, 'C': 0}
	for i in n:
		if i in d:
			d[i] += 1
		else:
			d[i] = 0
	if d['A'] + d['C'] == d['B']:
		print('YES')
	else:
		print('NO')
	t -= 1


for i in range(int(input())):
	string = input()
	if string.count('B') == string.count('A') + string.count('C'):
		print('YES')
	else:
		print('NO')


def func1(str1):
	(cA, cB, cC) = (0, 0, 0)
	for char1 in str1:
		if char1 == 'A':
			cA += 1
		elif char1 == 'B':
			cB += 1
		else:
			cC += 1
	if cA + cC == cB:
		return True
	return False
n = int(input())
for i in range(n):
	temp = input()
	if func1(temp):
		print('YES')
	else:
		print('NO')


numberofentries = int(input())
while numberofentries > 0:
	letters = str(input())
	lengthofletters = len(letters)
	if letters.count('B') == len(letters) / 2:
		print('YES')
	else:
		print('NO')
	numberofentries -= 1


t = int(input())
lst = []
for i in range(t):
	f = input()
	a = 0
	b = 0
	c = 0
	for j in f:
		if j == 'C':
			c += 1
		elif j == 'A':
			a += 1
		else:
			b += 1
	if b == a + c:
		lst.append('YES')
	else:
		lst.append('NO')
for i in range(t):
	print(lst[i])


t = int(input())
r = []
for i in range(t):
	s = input()
	if len(s) % 2 != 0:
		r.append('NO')
	elif s.find('B') == -1:
		r.append('NO')
	else:
		f = s.count('B')
		if f != len(s) // 2:
			r.append('NO')
		else:
			r.append('YES')
for i in range(len(r)):
	print(r[i])


t = int(input())
a = list()
for i in range(t):
	a.append(list(input()))
b = list()
for i in range(t):
	d = dict()
	for elem in a[i]:
		if elem not in d:
			d[elem] = 1
		else:
			d[elem] += 1
	b.append(d)
for i in range(t):
	if len(b[i]) == 3:
		if b[i]['B'] == b[i]['A'] + b[i]['C']:
			print('YES')
		else:
			print('NO')
	elif len(b[i]) == 1:
		print('NO')
	elif 'B' not in b[i]:
		print('NO')
	elif 'C' not in b[i] and b[i]['B'] == b[i]['A']:
		print('YES')
	elif 'C' not in b[i] and b[i]['B'] != b[i]['A']:
		print('NO')
	elif 'A' not in b[i] and b[i]['B'] == b[i]['C']:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	a_c = s.count('A')
	b_c = s.count('B')
	c_c = s.count('C')
	if a_c <= b_c and b_c - a_c == c_c:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	a = s.count('A')
	b = s.count('B')
	c = s.count('C')
	if b >= a:
		b = b - a
		if b == c:
			print('YES')
		else:
			print('NO')
	elif b >= c:
		b = b - c
		if b == a:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')