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.io.*;
  import java.lang.*;
  import java.util.*;
  import java.util.concurrent.PriorityBlockingQueue;
  
  //* --> number of prime numbers less then or equal to x are  -->  x/ln(x)
  //* --> String concatenation using the + operator within a loop should be avoided. Since the String object is immutable, each call for concatenation will
  // result in a new String object being created.
  // THE SIEVE USED HERE WILL RETURN A LIST CONTAINING ALL THE PRIME NUMBERS TILL N
  public class r1 {
  static class FastIO extends PrintWriter{private InputStream stream;private byte[] buf = new byte[1 << 16];
  private int curChar, numChars;public FastIO() {this(System.in, System.out);}public FastIO(InputStream i, OutputStream o){super(o);stream=i;}
  public FastIO(String i, String o) throws IOException{super(new FileWriter(o));stream = new FileInputStream(i);}
  private int nextByte(){if (numChars == -1)throw new InputMismatchException();if(curChar >= numChars) {
  curChar = 0;try{numChars = stream.read(buf);}catch (IOException e) {throw new InputMismatchException();}
  if (numChars == -1)return -1;}return buf[curChar++];}public String next(){int c;do{c=nextByte();}while (c <= ' ');StringBuilder res = new StringBuilder();do {
  res.appendCodePoint(c);c = nextByte();} while (c > ' ');return res.toString();}
  public int nextInt() { int c;do {c = nextByte();} while (c <= ' ');int sgn = 1;if (c == '-') {sgn = -1;c = nextByte();}
  int res = 0;do {if (c < '0' || c > '9')throw new InputMismatchException();res = 10 * res + c - '0';c = nextByte();
  } while (c > ' ');return res * sgn;}public int nextLong() {int c;do {c = nextByte();} while (c <= ' ');int sgn = 1;if (c == '-') {sgn = -1;c = nextByte();}int res = 0;do {if (c < '0' || c > '9')throw new InputMismatchException();
  res = 10 * res + c - '0';c = nextByte();} while (c > ' ');return res * sgn;}public double nextDouble() {return Double.parseDouble(next());}}
  public static void print(int ans, int t) {System.out.println("Case" + " " + "#" + t + ":" + " " + ans);}
  static long mod = 1000000007;static int max = Integer.MIN_VALUE;static int min = Integer.MAX_VALUE;
  public static void sort(long[] arr) {ArrayList<Long> ls = new ArrayList<Long>();for (long x : arr)ls.add(x);Collections.sort(ls);for (int i = 0; i < arr.length; i++)
  arr[i] = ls.get(i);}public static long fciel(long a, long b) {if (a == 0)return 0;return (a - 1) / b + 1;}
  static boolean[] is_prime = new boolean[1000001];static ArrayList<Integer> list = new ArrayList<>();static long n = 1000000;
  public static void sieve() {Arrays.fill(is_prime, true);is_prime[0] = is_prime[1] = false;for (int i = 2; i * i <= n; i++) {
  if (is_prime[i]){for (int j = i * i; j <= n; j += i)is_prime[j] = false;}}for (int i = 2; i <= n; i++) {if (is_prime[i]){list.add(i);}}
      }
  
      // ---------- NCR ---------- \
  
  static int NC = 100005;static long inv[] = new long[NC];static long fac_inv[] = new long[NC];static long fac[] = new long[NC];
  public static void initialize(){long MOD = mod;int i;inv[1] = 1;for (i = 2; i <= NC - 2; i++)inv[i] = (MOD - MOD / i) * inv[(int) MOD % i] % MOD;
  fac[0] = fac[1] = 1;for (i = 2; i <= NC - 2; i++)fac[i] = i * fac[i - 1] % MOD;fac_inv[0] = fac_inv[1] = 1;
  for (i = 2; i <= NC - 2; i++)fac_inv[i] = inv[i] * fac_inv[i - 1] % MOD;}public static long ncr(int n, int r) {
  long MOD = mod;if (n < r)return 0;return (fac[n] * fac_inv[r] % MOD) * fac_inv[n - r] % MOD;}
      
     // ---------- NCR ---------- \
  
  public static void main(String args[]) throws java.lang.Exception {FastIO io = new FastIO();StringBuilder s = new StringBuilder();
  int t=io.nextInt();while(t-->0){    
      char ar[]=io.next().toCharArray();
      int n=ar.length;
      int a=0;
      int b=0;
      int c=0;
      for(int i=0;i<n;i++)
      {
          if(ar[i]=='A')
          {
  a++;
          }
          else if(ar[i]=='B')
          {
              b++;
          }
          else{
              c++;
          }
      }
      s.append(b==a+c?"YES":"NO");
  if(t>0){s.append("\n");}}
  io.print(s);io.close();}}
  