Difficulty:1536
Expand

Learn the building blocks of programming languages
Take our free programming courses and learn to solve problems like these.
Start Learning

Binary Love

Alice and Bob are playing a game on a binary string SS of length NN.

Alice wants to make the number of substrings 01 and 10 equal, and both counts must be non-zero.
Formally, let c01c_{01} denote the number of indices ii (1i<N1 \le i \lt N) such that Si=0S_i = 0 and Si+1=1S_{i+1} = 1, and similarly let c10c_{10} denote the number of indices ii (1i<N1 \le i \lt N) such that Si=1S_i = 1 and Si+1=0S_{i+1} = 0.
Alice would like for c01=c10c_{01} = c_{10} and c01>0c_{01} \gt 0 to both hold.

Bob, on the other hand, wants to prevent Alice from achieving this condition.

The players take turns alternately, with Alice going first.
In each turn, the current player can remove exactly one character from either the beginning or the end of the string.

The game ends immediately when the string becomes empty or when Alice's desired condition (c01=c10>0c_{01} = c_{10} \gt 0) is satisfied.

If Alice can make the number of 01 and 10 substrings equal (and both non-zero), she wins.
Otherwise, if Bob can prevent this condition until the string becomes empty, Bob wins.
In particular, if the initial string satisfies the required condition, Alice wins immediately, without even having to make a move.

Determine the winner of the game if both players play optimally.

Input Format

  • The first line of input contains a single integer TT, denoting the number of test cases.
  • Each test case consists of two lines of input:
    • The first line contains a single integer NN — the length of the binary string.
    • The second line contains the binary string SS of length NN, consisting only of characters 0 and 1.

Output Format

For each test case, output a single string — Alice if Alice wins the game, or Bob if Bob wins the game.

You may print each character of the string in uppercase or lowercase (for example, the strings BOB, bOb, bob, and boB will all be treated as identical).

Constraints

  • 1T21051 \leq T \leq 2\cdot 10^5
  • 1N21051 \leq N \leq 2\cdot 10^5
  • Si{0,1}S_i \in \{0, 1\}
  • The sum of NN over all test cases won't exceed 21052\cdot10^5.

Sample 1:

Input
Output
4
3
000
3
010
4
0001
4
0101
Bob
Alice
Bob
Alice

Explanation:

Test case 11: We have c01=c10=0c_{01} = c_{10} = 0 for the initial string.
No matter what the players do in terms of deleting characters, this won't change.
Alice wants c01>0c_{01} \gt 0, so she cannot win here.

Test case 22: We have c01=c10=1c_{01} = c_{10} = 1 initially.
Alice's condition is already satisfied, so she wins immediately.

Test case 44: We have S=0101S = 0101, for which c01=2c_{01} = 2 and c10=1c_{10} = 1.
Alice must make a move; she can delete the last character to make S=010S = 010 which as seen earlier satisfies Alice's condition; so Alice wins.


More Info
Time limit1 secs
Memory limit1.5 GB
Source Limit50000 Bytes

Author(s)
Tester(s)
Editorialist(s)
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
}
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Visualize Code