#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt;
  cin >> tt;
  long long x = 1;
  while (tt--) {
    string s;
    cin >> s;
    long long ind = 0;
    long long n = s.size();
    for (long long i = 0; i < n; ++i) {
      if (s[i] == 'A') {
        ind = i;
        break;
      }
    }
    long long cntB = 0;
    long long p = 0;
    for (long long i = ind + 1; i < n; ++i) {
      if (s[i] == 'B') cntB++;
      p++;
    }
    if (p == 0) {
      cout << "Case #" << x << ": "
           << "Y"
           << "\n";
    } else if ((p + 1) / 2 <= cntB && cntB < p)
      cout << "Case #" << x << ": "
           << "Y"
           << "\n";
    else
      cout << "Case #" << x << ": "
           << "N"
           << "\n";
    x++;
  }
}
