#include <bits/stdc++.h>
using namespace std;
short dp[18][163][1 << 16];
int main(){
for (int i = 0; i < 18; i++){
for (int j = 0; j < 163; j++){
for (int k = 0; k < (1 << 16); k++){
dp[i][j][k] = 0;
}
}
}
for (int i = 0; i < 163; i++){
for (int j = 0; j < (1 << 16); j++){
int j2 = (j << 1) & ((1 << 16) - 1);
for (int k = 0; k < (i + 1) / 10; k++){
if ((j >> k & 1) == 0){
j2 |= 1;
}
}
dp[1][i][j] = j2;
}
}
for (int i = 2; i < 18; i++){
for (int j = 0; j < 163 - 9; j++){
for (int k = 0; k < (1 << 16)); k++){
int p = j;
for (int l = 0; l < 10; l++){
p = dp[i - 1][j + l][p];
}
dp[i][j][k] = p;
}
}
}
int t;
cin >> t;
for (int i = 0; i < t; i++){
long long n;
cin >> n;
if (n % 10 != 0){
cout << "Algosia" << endl;
} else {
string s = to_string(n);
int L = s.size();
int dsum = 0, p = (1 << 16) - 2;
for (int j = L - 1; j >= 1; j--){
int d = s[L - 1 - j] - '0';
for (int k = 0; k < d; k++){
p = dp[j][dsum][p];
dsum++;
}
}
if ((p & 1) == 0){
cout << "Bajtek" << endl;
} else {
cout << "Algosia" << endl;
}
}
}
}