/* Beautiful Codes are MUCH better than 'Shorter' ones ! user : triveni date : 22/04/2018 time : 08:14:21 */ #include using namespace std; #define pii std::pair #define vi std::vector #define sz(v) (int)(v.size()) #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define each(it,s) for(auto it = s.begin(); it != s.end(); ++it) #define rep(i, n) for(int i = 0; i < (n); ++i) #define rep1(i, n) for(int i = 1; i <= (n); ++i) #define all(v) v.begin(), v.end() #define scan(n) scanf("%d", &n) #define scan2(n, m) scanf("%d%d", &n, &m) #define pin(n) printf("%d\n",n) #define pis(n) printf("%d ",n) #define pll(n) printf("%lld\n", n) #define X first #define Y second typedef long long ll; const ll mod = 1000000007; inline int pow_(ll a, int n, int p=mod){ int r=1;while(n){if(n&1)r=r*a%p;n>>=1;a=a*a%p;}return r;} inline int inv_(int a) {return pow_(a, mod-2, mod);} inline int add(int a, int b){a+=b;if(a>=mod)a-=mod;return a;} inline void adds(int& a, int b){a+=b;if(a>=mod)a-=mod;} inline int mul(int a, int b){return a*1ll*b%mod;} inline void muls(int& a, int b){a=a*1ll*b%mod;} inline int sub(int a, int b){a-=b;if(a<0)a+=mod;return a;} int getInt(char endChar) { int x = 0; char ch = getchar(); assert(ch >= '0' && ch <= '9'); while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } assert(ch == endChar); return x; } string getString(char endChar) { string ans; char ch = getchar(); while(ch != endChar) { ans += ch; ch = getchar(); } assert(ch == endChar); return ans; } const bool BLACK = 0; const bool WHITE = 1; bool solve(string& s, int l, int r) { int n = sz(s); if(l < 0) return BLACK; if(r >= sz(s)) return WHITE; if(l + 1 == r) { // next to each other // ignore the white piece s[l] = '.'; int newL = l-1; while(newL >= 0 && s[newL] == '.') --newL; bool result = solve(s, newL, r); if(result == WHITE) return WHITE; // try capturing s[r] = 'W'; for (char & c : s) { if(c == 'W') c = 'B'; else if(c == 'B') c = 'W'; } reverse(all(s)); l = n-1; r = 0; while(l >= 0 && s[l] != 'W') --l; while(r < sz(s) && s[r] != 'B') ++r; result = solve(s, l, r); return result ^ WHITE; } else { int rightL = l + (r - l - 1) / 2; int leftR = rightL + 2; int whiteMove = 0, blackMove = 0; for (int i = l; i >= 0; --i) if(s[i] == 'W') { whiteMove += rightL - i; rightL -= 1; } for (int i = r; i < n; ++i) if(s[i] == 'B') { blackMove += i - leftR; leftR += 1; } return whiteMove > blackMove ? WHITE : BLACK; } } int main() { int T = getInt('\n'); assert(1 <= T && T <= 5e5); int N = 0; while(T--){ string s = getString('\n'); N += sz(s); assert(2 <= sz(s) && sz(s) <= 128); rep(i, sz(s)) assert(s[i]=='.'||s[i]=='W'||s[i]=='B'); assert(count(all(s), 'W') > 0); assert(count(all(s), 'B') > 0); int l = sz(s)-1, r = 0; while(s[l] != 'W') --l; while(s[r] != 'B') ++r; bool res = solve(s, l, r); puts(res == WHITE ? "W" : "B"); } assert(N <= 5e5); return 0; }