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: #include <bits/stdc++.h>
  using namespace std;
  template <typename T, typename U>
  inline void amin(T &x, U y) {
    if (y < x) x = y;
  }
  template <typename T, typename U>
  inline void amax(T &x, U y) {
    if (x < y) x = y;
  }
  template <typename T>
  inline void write(T x) {
    long long i = 20;
    char buf[21];
    buf[20] = '\n';
    do {
      buf[--i] = x % 10 + '0';
      x /= 10;
    } while (x);
    do {
      putchar(buf[i]);
    } while (buf[i++] != '\n');
  }
  template <typename T>
  inline T readInt() {
    T n = 0, s = 1;
    char p = getchar();
    if (p == '-') s = -1;
    while ((p < '0' || p > '9') && p != EOF && p != '-') p = getchar();
    if (p == '-') s = -1, p = getchar();
    while (p >= '0' && p <= '9') {
      n = (n << 3) + (n << 1) + (p - '0');
      p = getchar();
    }
    return n * s;
  }
  long long gcd(long long a, long long b) {
    if (a == 0) return b;
    if (b == 0) return a;
    if (a == b) return a;
    if (a > b)
      return gcd(a % b, b);
    else
      return gcd(a, b % a);
  }
  long long exp(long long x, long long n) {
    if (n == 0) return 1;
    if (n == 1) return x % 1000000007;
    if (n % 2 == 0)
      return exp((x * x) % 1000000007, n / 2);
    else
      return exp(x * exp((x * x) % 1000000007, n / 2));
  }
  bool sortbysec(const pair<long long, long long> &a,
                 const pair<long long, long long> &b) {
    return (a.second < b.second);
  }
  void solve() {
    string s;
    cin >> s;
    long long n = s.size();
    long long c1 = 0, c2 = 0, c3 = 0;
    for (long long i = 0; i < s.size(); i += 1) {
      if (s[i] == 'A')
        c1++;
      else if (s[i] == 'B')
        c2++;
      else
        c3++;
    }
    if (c1 <= c2) {
      n -= 2 * c1;
      c2 = c2 - c1;
      if (c2 == c3) {
        n -= 2 * c3;
      }
    }
    if (n == 0)
      cout << "YES\n";
    else
      cout << "NO\n";
    return;
  }
  int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long t = 1;
    cin >> t;
    for (long long i = 1; i <= t; i++) {
      solve();
    }
  }
  