Bit Game (Easy Version)
Contest: Codeforces Round 982 (Div. 2)
Difficulty rating: 2800
Tags: bitmasks, brute force, games, math

This is the easy version of this problem. The only difference is that you need to output the winner of the game in this version, and the number of stones in each pile are fixed. You must solve both versions to be able to hack.

Alice and Bob are playing a familiar game where they take turns removing stones from $$$n$$$ piles. Initially, there are $$$x_i$$$ stones in the $$$i$$$-th pile, and it has an associated value $$$a_i$$$. A player can take $$$d$$$ stones away from the $$$i$$$-th pile if and only if both of the following conditions are met:

- $$$1 \le d \le a_i$$$, and
- $$$x \, \& \, d = d$$$, where $$$x$$$ is the current number of stones in the $$$i$$$-th pile and $$$\&$$$ denotes the bitwise AND operation.

The player who cannot make a move loses, and Alice goes first.

You're given the $$$a_i$$$ and $$$x_i$$$ values for each pile, please determine who will win the game if both players play optimally.

Input format:
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.

The first line of each test case contains $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of piles.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i < 2^{30}$$$).

The third line of each test case contains $$$n$$$ integers $$$x_1, x_2, \ldots, x_n$$$ ($$$1 \le x_i < 2^{30}$$$).

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

Output format:
Print a single line with the winner's name. If Alice wins, print "Alice", otherwise print "Bob" (without quotes).

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

Note:
In the first test case, neither player can take any stones from the first pile since there is no value of $$$d$$$ satisfying the conditions. For the second pile, to begin with, Alice can remove between $$$1$$$ and $$$6$$$ stones. No matter which move Alice performs, Bob can remove the rest of the stones on his turn. After Bob's move, there are no more moves that Alice can perform, so Bob wins.

In the second test case, here is one example of how the game might go. Alice moves first, and she decides to remove from the first pile. She cannot take $$$17$$$ stones, because $$$17 > 10$$$, which fails the first condition. She cannot take $$$10$$$ stones, because $$$25 \, \& \, 10 = 8$$$ which fails the second condition. One option is to take $$$9$$$ stones; now the pile has $$$16$$$ stones left. On Bob's turn he decides to take stones from the second pile; the only option here is to take all $$$4$$$. Now, no more stones can be taken from either of the first two piles, so Alice must take some stones from the last pile. She decides to take $$$12$$$ stones, and Bob then follows by taking the last $$$2$$$ stones on that pile. Since Alice now has no legal moves left, Bob wins. It can be shown that no matter which strategy Alice follows, Bob will always be able to win if he plays optimally.

Example input:
7
2
1 6
10 7
3
10 8 15
25 4 14
4
8 32 65 64
7 45 126 94
3
20 40 1
23 55 1
5
12345 9876 86419 8641 1
6789 54321 7532 97532 1
2
20 64
44 61
3
57 109 55
69 90 85

Example output:
Bob
Bob
Bob
Bob
Bob
Alice
Alice

Editorial:
Each pile is an independent game, so let's try to find the nimber of a pile with value $$$a$$$ and size $$$x$$$ — let's denote this by $$$f(x, a)$$$. Suppose $$$x = 2^k - 1$$$ for some integer $$$k$$$; in this case, the nimber is entirely dependent on $$$a$$$. If $$$x$$$ is not in that form, consider the binary representation of $$$a$$$. If any bit in $$$a$$$ is on where $$$x$$$ is off, then it's equivalent to if $$$a$$$ had that bit off, but all lower bits were on. Let's call such a bit a 'good bit'. So we can build some value $$$a'$$$ by iterating along the bits from highest to lowest; if $$$x$$$ has an on bit in this position, then $$$a'$$$ will have an on bit in this position if and only if $$$a$$$ has one there, or we've already found a good bit. Now that the bits of $$$x$$$ and $$$a'$$$ align, we can remove all zeros from both representations and it's clear that this is an equivalent game with $$$x = 2^k - 1$$$.
One small observation to make is that we can remove the ones in $$$x$$$ which correspond to leading zeros in $$$a'$$$, since we can never use these. So actually, after calculating $$$a'$$$ we only need $$$g(a') = f(2^k - 1, a')$$$, where $$$k$$$ is the smallest integer such that $$$2^k - 1 \ge a'$$$. By running a brute force using the Sprague–Grundy theorem to find the nimbers you can observe some patterns which encompass all cases:
1. $$$g(2^k - 2) = 0$$$, for all $$$k \ge 1$$$.
2. $$$g(2^k - 1) = k$$$, for all $$$k \ge 0$$$.
3. $$$g(2^k) = k \oplus 1$$$, for all $$$k \ge 0$$$.
4. $$$g(2^k+1) = g(2^k+2) = \ldots = g(2^{k+1} - 3) = k + 1$$$, for all $$$k \ge 2$$$.
The first $$$3$$$ cases are nice and relatively simple to prove, but the last is a lot harder (at least, I couldn't find an easier way). Anyway, I will prove all of them here, for completeness.
First, note that if at any point we have $$$x \le a$$$, then we have a standard nim-game over the $$$k$$$ bits of the number, since we can remove any of them on each operation, so the nimber of such a game would be $$$k$$$. The second case is one example of this; we have $$$x = a = 2^k - 1$$$, so its nimber is $$$k$$$.
Now let's prove the first case. When $$$k = 1$$$, $$$g(0) = 0$$$ since there are no moves. For larger values of $$$k$$$, no matter which value of $$$d$$$ we choose, the resulting game has $$$x \le a$$$ where $$$x$$$ has a positive number of bits. Overall, we have the $$$\operatorname{mex}$$$ of a bunch of numbers which are all positive, so the nimber is $$$0$$$ as required.
Now let's prove the third case. To reiterate, since $$$a' = 2^k$$$ we have $$$x = 2^{k+1} - 1$$$ by definition. This case is equivalent to having a nim-game with one pile of $$$k$$$ bits (all bits below the most significant one), and another pile of $$$1$$$ bit (the most significant one). This is because we can remove any amount from either pile in one move, but never both. Therefore, the nimber is $$$k \oplus 1$$$ as required.
The last case is the hardest to prove. We need to show that there is some move that lands you in a game for all nimbers from $$$0$$$ to $$$k$$$, and never with nimber $$$k + 1$$$. Well, the only way that you could get a nimber of $$$k + 1$$$ is by landing in case $$$3$$$ without changing the number of bits in $$$x$$$/$$$a'$$$. Any move will change this though, since any move will remove some bits of $$$x$$$ and when $$$a'$$$ is recalculated it'll have fewer bits. Okay, now one way of getting a nimber of $$$0$$$ is just by removing all bits in $$$x$$$ which are strictly after the first zero-bit in $$$a'$$$. For example, if $$$a' = 101101$$$, then let's choose $$$d = 001111$$$; then we'll land in case $$$1$$$. As for getting the rest of the nimbers from $$$1$$$ to $$$k$$$, it helps if we can just land in case $$$2$$$ but with a varying number of bits. If $$$a' \ge 2^k + 2^{k-1} - 1$$$ this is easily possible by considering all $$$d$$$ in the range $$$2^k \le d < 2^k + 2^{k-1}$$$. On the other hand, if $$$a < 2^k + 2^{k-1} - 1$$$, let's first consider the resulting value of $$$x$$$ to be equal to $$$2^k + 2^m$$$, where $$$2^m$$$ is the lowest set bit in $$$a'$$$. This will give a nimber of $$$2$$$. Now, we can repeatedly add the highest unset bit in this $$$x$$$ to itself to generate the next nimber until we now have all nimbers from $$$2$$$ to $$$k$$$. For the nimber of $$$1$$$, just have the resulting $$$x$$$ be $$$2^k$$$.
Time complexity: $$$\mathcal{O}(n \log C)$$$, where $$$C$$$ is the upper limit on $$$x_i$$$.