Leftmost Pile First

medium games greedy arrays 1000 ms · 256 MB

Leftmost Pile First

Alice and Bob have lined up n piles of candies on the table, numbered from left to right; pile i holds a_i candies. They take turns, and Alice moves first. Bob insists on tidiness, so they agreed on one rule: on your turn you must eat at least one candy, and all the candies you eat must come from the leftmost pile that is not yet empty. You may eat as many candies from that pile as you like, up to the whole pile. A player who cannot make a move (because every pile is empty) loses.

Both players play optimally. Who wins?

Input

The first line contains an integer t (1 ≤ t ≤ 10^4), the number of test cases.

Each test case consists of two lines. The first contains an integer n (1 ≤ n ≤ 2·10^5), the number of piles. The second contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the pile sizes from left to right.

The sum of n over all test cases does not exceed 2·10^5.

Output

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

Notes

In the first test case of the first example the piles are 1 5 4. Alice has to eat the single candy of the first pile. Now Bob faces the pile of 5 and can eat 4 of its candies, leaving exactly one; Alice must eat it, Bob eats the whole last pile, and Alice has no move left. So Bob wins.

In the third test case of the first example every pile holds one candy, so no choice is ever possible: the players simply alternate, and Alice eats the last candy.

Example 1

Input

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

Output

Bob
Alice
Alice

Example 2

Input

3
1
7
2
1 1
5
2 1 1 1 1

Output

Alice
Bob
Alice

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

Hint 1

Look at what a single turn can do to the leftmost non-empty pile. If it holds one candy, the move is forced. If it holds several, does the player to move get to choose whether to leave the next player with a losing position?

Hint 2

Piles of one candy only pass the turn, so count the leading run of them and see who reaches the first pile of two or more. Everything after that pile is irrelevant. If all piles hold one candy, the parity of n decides the winner.

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

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