description: 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 ≤ t ≤ 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).
  
  Example
  
  Input
  
  
  6
  ABACAB
  ABBA
  AC
  ABC
  CABCBB
  BCBCBCBCBCBCBCBC
  
  
  Output
  
  
  NO
  YES
  NO
  NO
  YES
  YES
solution: 
  import java.util.*;
  
  
  import java.io.*;
  
  public class CF {
  	private static FS sc = new FS();
  	
  	private static class FS {
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st = new StringTokenizer("");
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st=new StringTokenizer(br.readLine());				               
  	            } catch (IOException e) {}
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
  	
  	private static class extra {
  		
  		static int[] intArr(int size) {
  			int[] a = new int[size];
  			for(int i = 0; i < size; i++) a[i] = sc.nextInt();
  			return a;
  		}
  		
  		static long[] longArr(int size) {
  			long[] a = new long[size];
  			for(int i = 0; i < size; i++) a[i] = sc.nextLong();
  			return a;
  		}
  		
  		static long intSum(int[] a) {
  			long sum = 0; 
  			for(int i = 0; i < a.length; i++) {
  				sum += a[i];
  			}
  			return sum;
  		}
  		
  		static long longSum(long[] a) {
  			long sum = 0; 
  			for(int i = 0; i < a.length; i++) {
  				sum += a[i];
  			}
  			return sum;
  		}
  		
  		static LinkedList[] graphD(int vertices, int edges) {
  			LinkedList<Integer>[] temp = new LinkedList[vertices+1];
  			for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
  			for(int i = 0; i < edges; i++) {
  				int x = sc.nextInt();
  				int y = sc.nextInt();
  				temp[x].add(y);
  			}
  			return temp;
  		}
  		
  		static LinkedList[] graphUD(int vertices, int edges) {
  			LinkedList<Integer>[] temp = new LinkedList[vertices+1];
  			for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
  			for(int i = 0; i < edges; i++) {
  				int x = sc.nextInt();
  				int y = sc.nextInt();
  				temp[x].add(y);
  				temp[y].add(x);
  			}
  			return temp;
  		}
  		
  		static void printG(LinkedList[] temp) {
  			for(LinkedList<Integer> aa:temp) System.out.println(aa);
  		}
  		
  		static long cal(long val, long pow, long mod) {
  			if(pow == 0) return 1;
  			long res = cal(val, pow/2, mod);
  			
  			long ret = (res*res)%mod;
  			if(pow%2 == 0) return ret;
  			return (val*ret)%mod;
  		}
  		
  		static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); }
  		
  	}
  	
  	static int mod = (int) 1e9 + 7;
  //	static int mod = (int) 998244353;
  	static LinkedList<Integer>[] temp, temp2;
  	static int inf = (int)1e9;
  	static long[] tree;
  	
  	public static void main(String[] args) {
  		int t = sc.nextInt();
  //		int t = 1;
  		StringBuilder ret = new StringBuilder();
  		while(t-- > 0) {
  			String s = sc.next();
  			int a = 0, b = 0, c = 0;
  			for(int i = 0; i < s.length(); i++) {
  				if(s.charAt(i) == 'A') a++;
  				else if(s.charAt(i) == 'B') b++;
  				else c++;
  			}
  			if(a > b) ret.append("NO\n");
  			else {
  				if(b-a == c) ret.append("YES\n");
  				else ret.append("NO\n");
  			}
  		}
  		System.out.println(ret);
  	}
  	
  }
  
  
  
  
  