Colouring Game
Contest: CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
Difficulty rating: 2600
Tags: constructive algorithms, dp, games

Alice and Bob are playing a game. There are $$$n$$$ cells in a row. Initially each cell is either red or blue. Alice goes first.

On each turn, Alice chooses two neighbouring cells which contain at least one red cell, and paints that two cells white. Then, Bob chooses two neighbouring cells which contain at least one blue cell, and paints that two cells white. The player who cannot make a move loses.

Find the winner if both Alice and Bob play optimally.

Note that a chosen cell can be white, as long as the other cell satisfies the constraints.

Input format:
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of test cases follows.

For each test case, the first line contains an integer $$$n$$$ ($$$2 \leq n \leq 5 \cdot 10^5$$$) — the number of cells.

The second line contains a string $$$s$$$ of length $$$n$$$ — the initial state of the cells. The $$$i$$$-th cell is red if $$$s_i = $$$ R, blue if $$$s_i = $$$ B.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.

Output format:
For each test case, output the name of the winner on a separate line.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the notes, the cell numbers increase from left to right.

In the first testcase for Alice, she has two choices: paint the first and the second cells, or paint the second and the third cells. No matter what choice Alice makes, there will be exactly one blue cell after Alice's move. Bob just needs to paint the blue cell and its neighbour, then every cell will be white and Alice can't make a move. So Bob is the winner.

In the second testcase no matter what Alice chooses, Bob can choose to paint the fourth and fifth cells in $$$2$$$ turns.

In the third testcase at first, Alice paints the third and the fourth cells. It doesn't matter if Bob paints the first and the second cells or the fifth and sixth cells, as Alice can paint the other two cells.

In the fourth testcase at first, Alice paints the second and the third cells. If Bob paints the fifth and the sixth cells or the fourth and the fifth cells, then Alice paints the seventh and the eighth cells. If Bob paints the seventh and the eighth cells, then Alice paints the fifth and the sixth cells.

In the fifth Alice chooses the middle two cells at first, then Bob obviously has only two options, whichever variant he chooses, Alice can choose the other one and win.

In the eighth no matter what Alice chooses, Bob can choose the other two symmetrical cells.

Example input:
8
3
BRB
5
RRBBB
6
RBRBRB
8
BBRRBRRB
6
BRRBRB
12
RBRBRBRBRRBB
12
RBRBRBRBBBRR
4
RBBR

Example output:
Bob
Bob
Alice
Alice
Alice
Alice
Bob
Bob

Editorial:
First, when the number red cells and blue cells are not equal, the player who owns a larger numberof his/her corresponding cells will win (Alice owns red and Bob owns blue). His/Her strategy can be: each time paint one segment of RB or BR white until there is none. This operation doesn't change the difference between the number of R and B and will decrease the number of the color of his/her opponent. Then Alice will only paint RW and WR, while Bob will only paint BW or WB. This operation will only decreace his/her own number of color, so the player who owns more cells of color will certainly win.
When the number of red cells and blue cells are the same, Alice and Bob will play games first on red-and-blue segments, until there is no RB or BR, and the player who faces this situation will lose.
Playing games on red-and-blue segments can be described as the following game: each player can take two neighbouring cells which has not be taken yet in his/her turn. As a result, this game becomes equal, then we can use SG function to forecast the result.
This SG function has the following calculating method: $$$SG(n)=mex_{i=0}^{n-2} SG(i)\oplus SG(n-2-i)$$$. In order to speed up, we can observe that $$${SG(i)}$$$ has a cyclic section of length $$$34$$$ except for the first few elements. It can also be proved by verifying the first $$$34^2$$$ elements has this cyclic section, and this demonstrates that for all kinds of xor combination of the cyclic section leads to this cycle. Use Mathematical Induction and we can know this combination will be the the same (just add some repeated numbers to the calculation of $$$mex$$$ as the previous $$$34$$$-th number) for the subsequent elements. The total time complexity can be reduced to $$$O(n)$$$ in calculating the SG function.