Take Up to K

easy games math 1000 ms · 256 MB

Take Up to K

Alice and Bob found a jar of n marbles on the porch and, naturally, turned it into a game. They take turns, and Alice goes first. On each turn the current player must remove at least 1 and at most k marbles from the jar, and never more than are left. Whoever removes the last marble keeps the whole jar and wins. Both of them play perfectly.

For each game, tell who wins. If Alice wins, also tell how many marbles she should take on her very first turn so that she still wins against Bob's best play. It can be shown that this number is unique.

Input

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

Each of the next t lines contains two integers n and k (1 ≤ n ≤ 10^18, 1 ≤ k ≤ 10^18), the number of marbles in the jar and the maximum number of marbles that may be taken in one turn.

Output

For each game print one line. If Bob wins, print Bob. Otherwise print Alice, a space, and the number x (1 ≤ x ≤ min(n, k)) of marbles Alice must take on her first turn to guarantee the win.

Notes

In the first example, in the first game (n = 5, k = 2) Alice takes 2 marbles and leaves 3. Bob takes 1 or 2 of them, and Alice takes the rest. In the second game (n = 6, k = 2), any first move by Alice leaves 5 or 4 marbles. Bob can then take enough to leave exactly 3 for Alice, and she loses as above.

In the second example, k ≥ n in the first game, so Alice simply empties the jar.

Example 1

Input

3
5 2
6 2
7 3

Output

Alice 2
Bob
Alice 3

Example 2

Input

5
4 10
1 1
2 1
9 4
10 3

Output

Alice 4
Alice 1
Bob
Alice 4
Alice 2

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

Hint 1

Start with small jars. Take k = 2 and try n from 1 to 10: for which sizes is the player to move in trouble? Look for a pattern in the sizes that are losing.

Hint 2

If each player always answers the other's move so that a full round removes the same fixed total, the losing jar sizes are the ones that are multiples of that total. What does that tell you about Alice's first move, and when it is unique?

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

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