problems / 139

Last Coin Loses

medium games bit-manipulation math 1000 ms · 256 MB

Last Coin Loses

There are n piles of coins on the table; pile i holds a_i coins (some piles may already be empty). Alice and Bob take turns, Alice first. On a turn, the player chooses one non-empty pile and removes any positive number of coins from it (possibly the whole pile).

The player who takes the very last coin on the table loses.

Both players play optimally. For each of several independent games, determine the winner.

Input

The first line contains T (1 ≤ T ≤ 10^5), the number of games.

Each game is described by two lines. The first contains n (1 ≤ n ≤ 10^5), the number of piles. The second contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^18), the pile sizes. At least one pile is non-empty.

The sum of n over all games does not exceed 10^5.

Output

For each game print one line: Alice if Alice wins with optimal play, otherwise Bob.

Notes

In the first example, the first game is a single pile of 1 coin: Alice is forced to take it and loses. In the second game (piles 1 and 1) Alice takes one coin, and Bob must take the last one. In the third game (a single pile of 5) Alice takes 4 coins and leaves Bob the last one. In the fourth game (piles 1, 2 and 3) every move Alice makes can be answered by Bob so that Alice eventually takes the last coin.

In the second example, the empty pile does not matter: with piles 1 and 1 Alice wins, and with piles 2 and 2 Bob mirrors Alice's moves until he can leave her a single coin.

Example 1

Input

4
1
1
2
1 1
1
5
3
1 2 3

Output

Bob
Alice
Alice
Bob

Example 2

Input

2
3
0 1 1
2
2 2

Output

Alice
Bob

Hints · reveal one at a time if you're stuck

Hint 1

Start with small cases: when every pile holds at most one coin, every move removes exactly one coin, so who takes the last coin? Compare this with ordinary Nim, where the XOR of pile sizes decides the winner, and see where the rule must differ.

Hint 2

If some pile has at least two coins, the usual Nim XOR test still decides the game, but when all piles are 0 or 1 the winner depends only on how many 1-piles there are. Compute the XOR with 64-bit integers, and do not let empty piles affect the parity count.

report an issue Prefer your own editor? sooks prep 139 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.