Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Bob and Alice are playing a game with the following rules:
Initially, they have an integer sequence $A_{1}, A_{2}, \ldots, A_{N}$; in addition, Bob has a *lucky number* $a$ and Alice has a lucky number $b$.
The players alternate turns. In each turn, the current player must remove a non-zero number of elements from the sequence; each removed element should be a multiple of the lucky number of this player.
If it is impossible to remove any elements, the current player loses the game.

It is clear that one player wins the game after a finite number of turns. Find the winner of the game if Bob plays first and both Bob and Alice play optimally.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains three space-separated integers $N$, $a$ and $b$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.

------  Output ------
For each test case, print a single line containing the string "ALICE" if the winner is Alice or "BOB" if the winner is Bob (without quotes).

------  Constraints  ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 2 \cdot 10^{5}$
$1 ≤ a, b ≤ 100$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$

------  Subtasks ------
Subtask #1 (18 points): $a = b$

Subtask #2 (82 points): original constraints

----- Sample Input 1 ------ 
2
5 3 2
1 2 3 4 5
5 2 4
1 2 3 4 5
----- Sample Output 1 ------ 
ALICE
BOB
----- explanation 1 ------ 
Example case 1: Bob removes $3$ and the sequence becomes $[1, 2, 4, 5]$. Then, Alice removes $2$ and the sequence becomes $[1, 4, 5]$. Now, Bob is left with no moves, so Alice is the winner.

Source: codechef | Difficulty: MEDIUM
Tags: Mathematics


Solutions:
def luckyNumberGame(nums, a, b):
	bobMoves = aliceMoves = commonMoves = 0
	for num in nums:
		if num % a == 0 and num % b == 0:
			commonMoves += 1
		elif num % a == 0:
			bobMoves += 1
		elif num % b == 0:
			aliceMoves += 1
	if commonMoves:
		bobMoves += 1
	if bobMoves > aliceMoves:
		return 'BOB'
	else:
		return 'ALICE'
t = int(input())
for _ in range(t):
	(n, a, b) = [int(x) for x in input().split()]
	nums = [int(x) for x in input().split()]
	print(luckyNumberGame(nums, a, b))


import numpy as np

def grab_input():
	(N, a, b) = input().split()
	N = int(N)
	a = int(a)
	b = int(b)
	numbers_in_string = input().split()
	for (i, num) in enumerate(numbers_in_string):
		numbers_in_string[i] = int(num)
	numbers = numbers_in_string
	return (numbers, a, b)
T = int(input())
for _ in range(T):
	(nums, a, b) = grab_input()
	alice = 0
	bob = 0
	d = 0
	for n in nums:
		if n % a == 0 and n % b == 0:
			d += 1
		elif n % a == 0:
			bob += 1
		elif n % b == 0:
			alice += 1
	if d > 0:
		bob += 1
	if bob > alice:
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for j in range(T):
	(N, a, b) = map(int, input().split(' '))
	arr: list = list(map(int, input().split(' ')))
	bob: int = 0
	alice: int = 0
	common: int = 0
	for i in range(N):
		if arr[i] % a == 0 and arr[i] % b == 0:
			common += 1
		elif arr[i] % a == 0:
			bob += 1
		elif arr[i] % b == 0:
			alice += 1
	if common > 0:
		bob += 1
	if bob > alice:
		print('BOB')
	else:
		print('ALICE')


def luckyNoGame(A, n, a, b):
	bob = 0
	for i in range(n):
		if not A[i] % a:
			bob += 1
		elif not A[i] % b:
			bob -= 1
	return 'BOB' if bob > 0 else 'ALICE'
for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	A = list(map(int, input().split()))
	print(luckyNoGame(A, n, a, b))


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	lst = list(map(int, input().split()))
	bob = 0
	for j in range(n):
		if lst[j] % a == 0:
			bob += 1
		elif lst[j] % b == 0:
			bob -= 1
	print('BOB') if bob > 0 else print('ALICE')


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	lst = list(map(int, input().split()))
	(bmov, almov, k) = (0, 0, 0)
	for j in range(n):
		if lst[j] % a == 0 and lst[j] % b == 0:
			k = 1
		elif lst[j] % a == 0:
			bmov += 1
		elif lst[j] % b == 0:
			almov += 1
	if k:
		bmov += 1
	if bmov > almov:
		print('BOB')
	else:
		print('ALICE')


from os import path
import sys
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	s = list(map(int, input().split()))
	com = 0
	bob = 0
	alice = 0
	for i in s:
		if i % a == i % b == 0:
			com += 1
		elif i % a == 0:
			bob += 1
		elif i % b == 0:
			alice += 1
	if com:
		bob += 1
	print(['BOB', 'ALICE'][alice >= bob])


T = int(input())
for i in range(T):
	(N, a, b) = map(int, input().split())
	l = map(int, input().split())
	a1 = 0
	b1 = 0
	for item in l:
		if item % a == 0:
			a1 += 1
		elif item % b == 0:
			b1 += 1
	if a1 > b1:
		print('BOB')
	else:
		print('ALICE')


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	nums = list(map(int, input().split()))
	bob_nums = 0
	alice_nums = 0
	shared_nums = 0
	for num in nums:
		if num % a == 0 and num % b == 0:
			shared_nums += 1
		elif num % a == 0:
			bob_nums += 1
		elif num % b == 0:
			alice_nums += 1
	if bob_nums > alice_nums:
		print('BOB')
	elif bob_nums == alice_nums:
		if shared_nums != 0:
			print('BOB')
		else:
			print('ALICE')
	elif alice_nums > bob_nums:
		print('ALICE')


for i in range(int(input())):
	[N, a, b] = [int(x) for x in input().split()]
	A = [int(a) for a in input().split()]
	if a == b:
		print('BOB')
	else:
		bob = [x for x in A if x % a == 0]
		alice = [x for x in A if x % b == 0]
		common = [i for i in bob if i in alice]
		bob = [x for x in bob if x not in common]
		alice = [x for x in alice if x not in common]
		if common:
			if len(bob) >= len(alice):
				print('BOB')
			else:
				print('ALICE')
		elif len(bob) > len(alice):
			print('BOB')
		else:
			print('ALICE')


t = int(input())
for ufrsg in range(t):
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	bob = 0
	alice = 0
	comm = 0
	for i in arr:
		if i % a == 0:
			bob += 1
		if i % b == 0:
			alice += 1
		d = a * b
		if i % d == 0:
			comm += 1
			bob -= 1
			alice -= 1
	if comm > 0:
		bob += 1
	if alice >= bob:
		print('ALICE')
	else:
		print('BOB')


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	alice = []
	bob = []
	common = []
	for i in arr:
		if i % a == 0 and i % b == 0:
			common.append(i)
		if i % a == 0:
			bob.append(i)
		if i % b == 0:
			alice.append(i)
	if len(alice) > len(bob) or len(bob) == 0 or len(common) == 0:
		print('ALICE')
	else:
		print('BOB')


for _ in range(int(input())):
	(N, a, b) = map(int, input().split())
	A = list(map(int, input().split()))
	bob = alc = c = 0
	for i in A:
		if i % a == 0 and i % b == 0:
			c += 1
		elif i % a == 0:
			bob += 1
		elif i % b == 0:
			alc += 1
	if c:
		bob += 1
	if bob > alc:
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for _ in range(T):
	(N, a, b) = map(int, input().split())
	p = 0
	m = 0
	n = 0
	for elem in map(int, input().split()):
		if elem % a == 0 and elem % b == 0:
			p += 1
		elif elem % a == 0:
			n += 1
		elif elem % b == 0:
			m += 1
	if p == 0:
		if n > m:
			winner = 'BOB'
		else:
			winner = 'ALICE'
	elif n >= m:
		winner = 'BOB'
	else:
		winner = 'ALICE'
	print(winner)


for i in range(int(input())):
	(n, b, a) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	ac = 0
	bc = 0
	c = 0
	for j in l:
		if j % b == 0:
			bc += 1
			c += 1
		elif j % a == 0:
			ac += 1
			c += 1
	if bc > ac or (bc == ac and c == bc and (c % 2 != 0)):
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for i in range(T):
	score = [0, 0]
	(N, a, b) = map(int, input().split())
	A = list(map(int, input().split()))
	empate = False
	for j in range(N):
		if A[j] % a == 0 and A[j] % b == 0:
			empate = True
		elif A[j] % a == 0:
			score[0] += 1
		elif A[j] % b == 0:
			score[1] += 1
	if empate:
		score[0] += 1
	if score[0] > score[1]:
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for x in range(T):
	score = [0, 0]
	(N, a, b) = map(int, input().split())
	A = list(map(int, input().split()))
	for y in range(N):
		if A[y] % a == 0 and A[y] % b == 0 or A[y] % a == 0:
			score[0] += 1
		elif A[y] % b == 0:
			score[1] += 1
	if score[0] > score[1]:
		print('BOB')
	else:
		print('ALICE')


for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	p = 0
	q = 0
	for i in range(n):
		if c[i] % a == 0:
			p += 1
		elif c[i] % b == 0:
			q += 1
	if p > q:
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for _ in range(T):
	(N, a, b) = map(int, input().split())
	A = list(map(int, input().split()))
	flag = False
	for i in range(N):
		if A[i] % a == 0:
			flag = True
			break
	if not flag:
		print('ALICE')
		continue
	flag = False
	for i in range(N):
		if A[i] % b == 0:
			flag = True
			break
	if not flag:
		print('BOB')
		continue
	if b % a == 0:
		print('BOB')
		continue
	Alice = 0
	Bob = 0
	both = 0
	for i in range(N):
		if A[i] % b == 0 and A[i] % a == 0:
			both += 1
		elif A[i] % b == 0:
			Alice += 1
		elif A[i] % a == 0:
			Bob += 1
	if Bob > Alice or (Bob == Alice and both > 0):
		print('BOB')
	else:
		print('ALICE')


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	arr = [int(a) for a in input().split()]
	al = 0
	bo = 0
	for i in arr:
		if i % a == 0:
			bo += 1
		elif i % b == 0:
			al += 1
		else:
			continue
	if al >= bo:
		print('ALICE')
	else:
		print('BOB')


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	Bob = []
	Alice = []
	both = []
	for o in l:
		if o % a == 0 and o % b == 0:
			both.append(o)
		elif o % a == 0:
			Bob.append(o)
		elif o % b == 0:
			Alice.append(o)
	if len(both):
		Bob.append(1)
	if len(Bob) > len(Alice):
		print('BOB')
	else:
		print('ALICE')


for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	ar = input().split()
	A = [int(i) for i in ar]
	bob = alice = common = 0
	for x in A:
		if x % a == 0 and x % b == 0:
			common += 1
		elif x % a == 0:
			bob += 1
		elif x % b == 0:
			alice += 1
	if common:
		bob += 1
	if bob > alice:
		print('BOB')
	else:
		print('ALICE')


for i in range(int(input())):
	(n, ai, bi) = map(int, input().split())
	data = list(map(int, input().split()))
	a = 0
	b = 0
	for d in data:
		if d % ai == 0:
			a += 1
		elif d % bi == 0:
			b += 1
	if a - b > 0:
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for t in range(T):
	(N, a, b) = input().split()
	A = list(map(int, input().split()))
	no_of_integers = int(N)
	Bob_lucky_no = int(a)
	Alice_lucky_no = int(b)
	bob_moves = 0
	alice_moves = 0
	for i in A:
		if i % Bob_lucky_no == 0:
			bob_moves = bob_moves + 1
		elif i % Alice_lucky_no == 0:
			alice_moves = alice_moves + 1
	if bob_moves > alice_moves:
		print('BOB')
	else:
		print('ALICE')


def lucky(list1, a, b):
	bob = alice = common = 0
	for i in list1:
		if i % a == 0 and i % b == 0:
			common += 1
		elif i % a == 0:
			bob += 1
		elif i % b == 0:
			alice += 1
	if common:
		bob += 1
	if bob > alice:
		print('BOB')
	else:
		print('ALICE')
tc = int(input())
for _ in range(tc):
	(n, a, b) = [int(i) for i in input().split()]
	ele = list(map(int, input().split()))
	lucky(ele, a, b)


for _ in range(int(input())):
	(n, b, a) = map(int, input().split())
	arr = list(map(int, input().split()))
	(bob, alice, common) = (0, 0, 0)
	for i in arr:
		if i % b == 0 and i % a == 0:
			common += 1
			continue
		if i % b == 0:
			bob += 1
		if i % a == 0:
			alice += 1
	if common > 0 and bob >= alice:
		print('BOB')
	elif bob > alice:
		print('BOB')
	else:
		print('ALICE')


t = int(input())
for _ in range(t):
	params = input().split()
	values = input().split()
	a = 0
	b = 0
	c = 0
	for i in values:
		if int(i) % int(params[1]) == 0 and int(i) % int(params[2]) == 0:
			c += 1
		elif int(i) % int(params[1]) == 0:
			a += 1
		elif int(i) % int(params[2]) == 0:
			b += 1
	if c > 0:
		a += 1
	if a > b:
		print('BOB')
	else:
		print('ALICE')


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	array = list(map(int, input().split()))
	both = bob = alice = 0
	for i in array:
		if i % a == 0 and i % b == 0:
			both += 1
			bob += 1
			alice += 1
		elif i % a == 0:
			bob += 1
		elif i % b == 0:
			alice += 1
		else:
			pass
	if both != 0:
		if bob - both >= alice - both:
			print('BOB')
		else:
			print('ALICE')
	elif alice >= bob:
		print('ALICE')
	else:
		print('BOB')


t = int(input())
while t > 0:
	t = t - 1
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c3 = 0
	for i in l:
		if i % a == 0:
			c1 = c1 + 1
		if i % b == 0:
			c2 = c2 + 1
		if i % a == 0 and i % b == 0:
			c3 = c3 + 1
	c1 = c1 - c3
	c2 = c2 - c3
	if c3 == 0:
		if c1 > c2:
			print('BOB')
		else:
			print('ALICE')
	elif c1 >= c2:
		print('BOB')
	else:
		print('ALICE')


t = int(input())
while t:
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	(b1, a1, c1) = (0, 0, 0)
	for i in l:
		if i % a == 0:
			b1 += 1
		if i % b == 0:
			a1 += 1
		if i % a == 0 and i % b == 0:
			c1 += 1
	if c1 > 0:
		b1 += 1
	print('BOB') if b1 > a1 else print('ALICE')
	t -= 1


t = int(input())
for i in range(t):
	A = 0
	B = 0
	C = 0
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	for j in range(len(arr)):
		if arr[j] % a == 0 and arr[j] % b == 0:
			C += 1
		elif arr[j] % a == 0:
			B += 1
		elif arr[j] % b == 0:
			A += 1
	if C > 0:
		B = B + 1
	if B > A:
		print('BOB')
	else:
		print('ALICE')


for _ in range(int(input())):
	(ele, bob, alice) = list(map(int, input().split()))
	thingy = list(map(int, input().split()))
	boths = 0
	bobs = 0
	alices = 0
	for num in range(ele):
		if thingy[num] % bob == 0 and thingy[num] % alice == 0:
			boths += 1
		elif thingy[num] % bob == 0:
			bobs += 1
		elif thingy[num] % alice == 0:
			alices += 1
	if boths >= 1:
		bobs += 1
	if bobs > alices:
		print('BOB')
	else:
		print('ALICE')


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = [int(k) for k in input().split()]
	(x, y, z) = [0] * 3
	for i in l:
		if i % a == 0:
			if i % b == 0:
				z += 1
			else:
				x += 1
		elif i % b == 0:
			y += 1
	if z:
		print(('BOB', 'ALICE')[x + 1 <= y])
	else:
		print(('BOB', 'ALICE')[x <= y])


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	c1 = 0
	c2 = 0
	for i in l:
		if i > 0:
			if i % a == 0:
				c1 += 1
			elif i % b == 0:
				c2 += 1
	if c1 > c2:
		print('BOB')
	else:
		print('ALICE')


def gcd(A, B):
	if A == 0:
		return B
	return gcd(B % A, A)

def lcm(A, B):
	return A / gcd(A, B) * B
t = int(input())
for _ in range(t):
	(n, B, A) = [int(x) for x in input().split()]
	lst = [int(x) for x in input().split()]
	h = lcm(A, B)
	lst.sort()
	a = []
	b = []
	hh = []
	for l in lst:
		if l % h == 0:
			hh.append(l)
		elif l % A == 0:
			a.append(l)
		elif l % B == 0:
			b.append(l)
	at = len(a)
	bt = len(b)
	if len(hh) > 0:
		bt += 1
	if at >= bt:
		print('ALICE')
	else:
		print('BOB')


for _ in range(int(input())):
	(N, a, b) = input().split()
	N = int(N)
	a = int(a)
	b = int(b)
	A = input().split()
	(com, na, nb) = (0, 0, 0)
	for i in range(N):
		A[i] = int(A[i])
		if A[i] % a == 0 and A[i] % b == 0:
			com += 1
		elif A[i] % a == 0:
			na += 1
		elif A[i] % b == 0:
			nb += 1
	if a == b:
		print('BOB')
	elif na > nb:
		print('BOB')
	elif na < nb:
		print('ALICE')
	elif com != 0:
		print('BOB')
	else:
		print('ALICE')


t = int(input())
for _ in range(t):
	list1 = []
	(N, a, b) = map(int, input().split())
	list1 = list(map(int, input().split()))
	c = 0
	d = 0
	e = 0
	for num in list1:
		if num % a == 0 and num % b == 0:
			c += 1
		elif num % a == 0:
			d += 1
		elif num % b == 0:
			e += 1
	if c:
		d += 1
	if d > e:
		print('BOB')
	else:
		print('ALICE')


for _ in range(int(input())):
	(n, b, a) = map(int, input().split())
	s = list(map(int, input().split()))
	bm = 0
	am = 0
	Lm = 0
	for i in range(n):
		if s[i] % b == 0 and s[i] % a == 0:
			Lm += 1
		elif s[i] % b == 0:
			bm += 1
		elif s[i] % a == 0:
			am += 1
	if Lm != 0:
		bm += 1
	if bm > am:
		print('BOB')
	else:
		print('ALICE')


T = int(input())
for i in range(T):
	INP = list(map(int, input().split()))
	N = INP[0]
	b = INP[1]
	a = INP[2]
	A = list(map(int, input().split()))
	ALI = 0
	BOB = 0
	BLI = False
	for j in A:
		if j % b == 0 and j % a == 0:
			BLI = True
		elif j % a == 0:
			ALI += 1
		elif j % b == 0:
			BOB += 1
	ALI -= int(BLI)
	if BOB <= ALI:
		print('ALICE')
	else:
		print('BOB')


def bob_winner(A, a, b):
	both = [x for x in A if x % a == 0 and x % b == 0]
	if a == b:
		return len(both) > 0
	bobs_only = [x for x in A if x not in both and x % a == 0]
	alices_only = [x for x in A if x not in both and x % b == 0]
	if len(both) == 0:
		return len(bobs_only) > len(alices_only)
	return len(bobs_only) >= len(alices_only)

def main():
	T = int(input())
	for i in range(T):
		(N, a, b) = [int(x) for x in input().split(' ')]
		A = [int(x) for x in input().split(' ')]
		if bob_winner(A, a, b):
			print('BOB')
		else:
			print('ALICE')
main()


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	lis = list(map(int, input().split()))
	alice = []
	bob = []
	for i in range(n):
		if lis[i] % a == 0:
			bob.append(lis[i])
		elif lis[i] % b == 0:
			alice.append(lis[i])
	if len(bob) > len(alice):
		print('BOB')
	elif len(bob) == len(alice):
		print('ALICE')
	else:
		print('ALICE')


t = int(input())
while t:
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().strip().split()))[:n]
	x = y = 0
	for i in range(n):
		if l[i] % a == 0:
			x += 1
		elif l[i] % b == 0:
			y += 1
	if x > y:
		print('BOB')
	else:
		print('ALICE')
	t -= 1


for temp in range(int(input())):
	(n, a, b) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	cm = 0
	am = 0
	bm = 0
	for i in arr:
		if i % a == 0 and i % b == 0:
			cm += 1
		elif i % b == 0:
			am += 1
		elif i % a == 0:
			bm += 1
	if cm > 0:
		bm += 1
	if bm > am:
		print('BOB')
	else:
		print('ALICE')


def game_of_multiple(n, a, b, A):
	cnt_a = 0
	cnt_b = 0
	same = 0
	for i in range(n):
		if A[i] % a == 0:
			cnt_a += 1
		if A[i] % b == 0:
			cnt_b += 1
		if A[i] % a == 0 and A[i] % b == 0:
			same += 1
	if cnt_a > cnt_b - same:
		return 'BOB'
	elif cnt_a <= cnt_b - same:
		return 'ALICE'
t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	A = list(map(int, input().split()))
	result = game_of_multiple(n, a, b, A)
	print(result)


for _ in range(int(input())):
	(n, a, b) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	bob = 0
	alice = 0
	same = 0
	for num in arr:
		if num % a == 0:
			bob += 1
		if num % b == 0:
			alice += 1
		if num % a == 0 and num % b == 0:
			same += 1
	if bob > alice - same:
		print('BOB')
	elif bob <= alice - same:
		print('ALICE')


def Game(X, a, b):
	p = q = commonMoves = 0
	for i in X:
		if i % a == 0 and i % b == 0:
			commonMoves += 1
		elif i % a == 0:
			p += 1
		elif i % b == 0:
			q += 1
	if commonMoves:
		p += 1
	if p > q:
		return 'BOB'
	else:
		return 'ALICE'
t = int(input())
for _ in range(t):
	(n, a, b) = [int(x) for x in input().split()]
	X = [int(x) for x in input().split()]
	print(Game(X, a, b))


for _ in range(int(input())):
	(n, a, b) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	bob = 0
	alice = 0
	for i in range(n):
		if l[i] % a == 0:
			bob += 1
		elif l[i] % b == 0:
			alice += 1
	if bob > alice:
		print('BOB')
	else:
		print('ALICE')


t = int(input())
for i in range(t):
	(N, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	B = A = 0
	for i in l:
		if i % a == 0:
			B += 1
		elif i % b == 0:
			A += 1
	if B > A:
		print('BOB')
	else:
		print('ALICE')


t = int(input())
while t:
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	flag_a = 0
	flag_b = 0
	for i in range(len(arr)):
		if arr[i] % a == 0:
			flag_b += 1
		elif arr[i] % b == 0:
			flag_a += 1
	if flag_b > flag_a:
		print('BOB')
	else:
		print('ALICE')
	t -= 1


t = int(input())
for tt in range(t):
	sump = 0
	sumo = 0
	(n, a, b) = [int(x) for x in input().split()]
	cn = [int(x) for x in input().split()]
	if a == b:
		print('BOB')
	elif a == 0:
		for i in cn:
			if i != 0 and i % b == 0:
				print('ALICE')
				break
		else:
			print('BOB')
	elif b == 0:
		for i in cn:
			if i != 0 and i % a == 0:
				print('BOB')
				break
		else:
			print('ALICE')
	else:
		for i in cn:
			if i != 0 and i % a == 0:
				sump = sump + 1
		for i in cn:
			if i != 0 and i % b == 0 and (i % a != 0):
				sumo = sumo + 1
		if sump > 0 and sumo == 0:
			print('BOB')
		elif sumo > 0 and sump == 0:
			print('ALICE')
		elif sump == 0 and sumo == 0:
			print('ALICE')
		elif sumo > sump:
			print('ALICE')
		elif sump == sumo:
			print('ALICE')
		else:
			print('BOB')