#include <iostream>
#include <cstdio>
#include <cmath>
using
namespace
std;
int
ans = 0;
int
flag = 0;
int
t1 = 0;
int
t2 = 0;
void
primeFactor(
int
n){
while
(n % 2 == 0){
//printf("2 ");
ans = 1;
n /= 2;
t1 ++;
flag = 1;
}
for
(
int
i = 3; i <=
sqrt
(n); i += 2){
int
t = n;
while
(n % i == 0){
//printf("%d ", i);
n /= i;
if
(flag == 0){
t1 ++;
}
else
{
t2 ++;
}
}
if
(t1 != 0){
flag = 1;
}
if
(t != n){
ans ++;
}
}
if
(n > 2){
ans ++;
//printf("%d ", n);
if
(flag == 0){t1 ++;}
else
{t2 ++;}
}
}
int
main(){
int
n,T;
char
in[100];
scanf
(
"%d"
,&T);
while
(T --){
scanf
(
"%d%s"
,&n,in);
flag = 0;t1 = 0;t2 = 0;
ans = 0;
primeFactor(n);
//printf("
%d
",ans);
//printf("%d %d
",t1,t2);
if
(ans >= 3){
printf
(
"tie
"
);}
else
{
if
(ans == 1){
if
(t1 % 2 == 0){
if
(in[0] ==
'A'
){
printf
(
"Bob
"
);}
else
{
printf
(
"Alice
"
);}
}
else
{
if
(in[0] ==
'B'
){
printf
(
"Bob
"
);}
else
{
printf
(
"Alice
"
);}
}
}
else
if
(ans == 2){
if
(t1 == t2){
if
(in[0] ==
'A'
){
printf
(
"Bob
"
);}
else
{
printf
(
"Alice
"
);}
}
else
if
(max(t1,t2) - min(t1,t2) == 1){
if
(in[0] ==
'B'
){
printf
(
"Bob
"
);}
else
{
printf
(
"Alice
"
);}
}
else
if
(max(t1,t2) - min(t1,t2) > 1){
printf
(
"tie
"
);
}
}
}
}
return
0;
}