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: /*
  +-------------------------------+
  | Written by Kabir Kanha Arora. |
  |   @kabirkanha  |    @Kabir    |
  +-------------------------------+
   */
  
  import java.io.*;
  import java.util.*;
  
  public class Main {
  
      static long[] fact;
      static boolean[] visited;
      static ArrayList<ArrayList<Pair>> adjList;
      static int[][] shortestDistance;
      static FastScanner scanner = new FastScanner();
      static PrintWriter out = new PrintWriter(System.out);
  
      static long MOD = 1000000007;
  
      public static void main(String[] args) {
          int t = scanner.nextInt();
          while (t-- > 0) {
              char[] arr = scanner.next().toCharArray();
              int A_Cnt = 0;
              int B_Cnt = 0;
              int C_Cnt = 0;
              for (char ch : arr) {
                  if (ch == 'A')
                      ++A_Cnt;
                  else if (ch == 'B')
                      ++B_Cnt;
                  else if (ch == 'C')
                      ++C_Cnt;
              }
              if (B_Cnt == A_Cnt + C_Cnt)
                  System.out.println("YES");
              else
                  System.out.println("NO");
          }
          out.close();
      }
  
      /*
      +--------------------------------------------+
      | METHODS BELOW THIS LINE ARE TEMPLATE CODE. |
      +--------------------------------------------+
       */
  
      // Shuffle and sort array
      static void shuffleAndSort(int[] arr) {
          for (int i = 0; i < arr.length; ++i) {
              int random_index = (int) (Math.random() * arr.length);
              int temp = arr[i];
              arr[i] = arr[random_index];
              arr[random_index] = temp;
          }
          Arrays.sort(arr);
      }
  
      // Pair class
      static class Pair {
          int first;
          int second;
  
          Pair(int first, int second) {
              this.first = first;
              this.second = second;
          }
      }
  
      // Sort array of pairs in asc order by first elem
      static void sortPairByFirst(Pair[] arr) {
          Arrays.sort(arr, Comparator.comparingInt(o -> o.first));
      }
  
      // Sort array of pairs in asc order by second elem
      static void sortPairBySecond(Pair[] arr) {
          Arrays.sort(arr, Comparator.comparingInt(o -> o.second));
      }
  
      // Triplet class
      static class Triplet {
          int first;
          int second;
          int third;
  
          Triplet(int first, int second, int third) {
              this.first = first;
              this.second = second;
              this.third = third;
          }
      }
  
      // Swap two elements of an int array
      static void swap(int[] arr, int left, int right) {
          int temp = arr[left];
          arr[left] = arr[right];
          arr[right] = temp;
      }
  
      // Swap two elements of a String array
      static void swap(String[] arr, int left, int right) {
          String temp = arr[left];
          arr[left] = arr[right];
          arr[right] = temp;
      }
  
      // Reverse an int subarray
      static void reverse(int[] arr, int left, int right) {
          while (left < right) {
              swap(arr, left++, right--);
          }
      }
  
      // Reverse a String subarray
      static void reverse(String[] arr, int left, int right) {
          while (left < right) {
              swap(arr, left++, right--);
          }
      }
  
      // Binary search to find the first element >= num
      // a.k.a lower_bound()
      static int atLeastN(int[] arr, int start, int end, int num) {
          if (arr[end] < num)
              return -1;
          while (start < end) {
              int mid = (start + end) / 2;
              if (arr[mid] < num)
                  start = mid + 1;
              else
                  end = mid;
          }
          return start;
      }
  
      // Binary search to find the last element <= num
      static int atMostN(int[] arr, int start, int end, int num) {
          if (arr[start] > num)
              return -1;
          while (start < end) {
              int mid = (start + end + 1) / 2;
              if (arr[mid] > num)
                  end = mid - 1;
              else
                  start = mid;
          }
          return start;
      }
  
      // Find next permutation of an int array
      public static boolean nextPermutation(int[] arr) {
          if (arr.length <= 1)
              return false;
          int last = arr.length - 2;
  
          // Find longest non-increasing suffix and pivot
          while (last >= 0) {
              if (arr[last] < arr[last + 1]) {
                  break;
              }
              last--;
          }
  
          // No increasing pair found
          if (last < 0)
              return false;
  
          // Find the rightmost successor to the pivot
          int nextGreater = arr.length - 1;
          for (int i = arr.length - 1; i > last; i--) {
              if (arr[i] > arr[last]) {
                  nextGreater = i;
                  break;
              }
          }
  
          // Swap the successor and the pivot
          swap(arr, nextGreater, last);
          // Reverse the suffix
          reverse(arr, last + 1, arr.length - 1);
          // Found next_permutation
          return true;
      }
  
      // Find next permutation of a String array
      public static boolean nextPermutation(String[] arr) {
          if (arr.length <= 1)
              return false;
          int last = arr.length - 2;
  
          // Find longest non-increasing suffix and pivot
          while (last >= 0) {
              if (arr[last].compareTo(arr[last + 1]) < 0) {
                  break;
              }
              last--;
          }
  
          // No increasing pair found
          if (last < 0)
              return false;
  
          // Find the rightmost successor to the pivot
          int nextGreater = arr.length - 1;
          for (int i = arr.length - 1; i > last; i--) {
              if (arr[i].compareTo(arr[last]) > 0) {
                  nextGreater = i;
                  break;
              }
          }
  
          // Swap the successor and the pivot
          swap(arr, nextGreater, last);
          // Reverse the suffix
          reverse(arr, last + 1, arr.length - 1);
          // Found next_permutation
          return true;
      }
  
      // Compute Factorials
      static void preComputeFactorials(int SIZE) {
          fact = new long[SIZE + 1];
          fact[0] = 1;
          fact[1] = 1;
          for (int i = 2; i <= SIZE; ++i)
              fact[i] = i * fact[i - 1];
      }
  
      // Combinations
      static long nCr(int n, int r) {
          if (n < r)
              return 0;
          return (fact[n] * ((inv(fact[r]) * inv(fact[n - r])) % MOD)) % MOD;
      }
  
      // Modular inverse
      static long inv(long x) {
          return power(x, MOD - 2);
      }
  
      // Binary exponentiation
      static long power(long x, long y) {
          long res = 1;
          x %= MOD;
          while (y > 0) {
              if (y % 2 == 1)
                  res = (res * x) % MOD;
              y = y >> 1;
              x = (x * x) % MOD;
          }
          return res;
      }
  
      // Create adjacency lists for graph
      static void createAdjLists(int n, boolean weighted, boolean directed) {
          for (int i = 0; i < n; ++i) {
              ArrayList<Pair> temp = new ArrayList<>();
              adjList.add(temp);
          }
          for (int i = 0; i < n - 1; ++i) {
              int v1 = scanner.nextInt() - 1;
              int v2 = scanner.nextInt() - 1;
              int weight = weighted ? scanner.nextInt() : 0;
              adjList.get(v1).add(new Pair(v2, weight));
              if (!directed)
                  adjList.get(v2).add(new Pair(v1, weight));
          }
      }
  
      // DFS
      static void dfs(int root) {
          visited[root] = true;
          out.println(root);
          for (Pair pair : adjList.get(root)) {
              int node = pair.first;
              int weight = pair.second;
              if (!visited[node]) {
                  dfs(node);
              }
          }
      }
  
      // Floyd-Warshall Algorithm - O(V^3)
      static void floydWarshall() {
          int V = shortestDistance.length;
          for (int i = 0; i < V; ++i)
              shortestDistance[i][i] = 0;
          for (int k = 0; k < V; k++) {
              for (int i = 0; i < V; i++) {
                  for (int j = 0; j < V; j++) {
                      if (shortestDistance[i][k] != -1 && shortestDistance[k][j] != -1) {
                          if ((shortestDistance[i][k] + shortestDistance[k][j] < shortestDistance[i][j]) || (shortestDistance[i][j] == -1)) {
                              shortestDistance[i][j] = shortestDistance[i][k] + shortestDistance[k][j];
                          }
                      }
                  }
              }
          }
      }
  
      // Check if a string is a palindrome
      static boolean checkPalindrome(String str) {
          StringBuilder str_rev = new StringBuilder(str);
          str_rev.reverse();
          return str.equals(str_rev.toString());
      }
  
      // Fast IO
      static class FastScanner {
  
          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) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          int[] readArray(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; ++i) a[i] = nextInt();
              return a;
          }
  
          long[] readLongArray(int n) {
              long[] a = new long[n];
              for (int i = 0; i < n; ++i) a[i] = nextLong();
              return a;
          }
      }
  }
  
  /*
  Are you sure you covered all the edge cases?
   */
  