// #pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define int __int128
#define all(x) x.begin(), x.end()
// #define int long long
// #define double long double
using ull = unsigned long long;
using ll = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<int> cnta(n + m + 1), cntb(n + m + 1);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
cnta[x]++;
}
for (int i = 0; i < m; ++i) {
int x;
cin >> x;
cntb[x]++;
}
vector<int> cnt(n + m + 1);
for (int x = 1; x <= n + m; ++x) {
for (int y = x; y <= n + m; y += x) {
cnt[y] += cnta[x];
}
}
int ca = 0, cb = 0, cc = 0;
for (int x = 1; x <= n + m; ++x) {
if (cnt[x] > 0 && cnt[x] < n)
cc += cntb[x];
else if (cnt[x] == 0)
cb += cntb[x];
else
ca += cntb[x];
}
if (cc % 2 == 0) {
if (ca > cb) {
cout << "Alice\n";
} else {
cout << "Bob\n";
}
} else {
if (ca >= cb) {
cout << "Alice\n";
} else {
cout << "Bob\n";
}
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(20);
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}