#include<bits/stdc++.h>
using namespace std ;
int t , k , n ;
bool kb( int k , int n )
{
int sum ;
while( n > 0 )
{
n %= 10 ;
n /= 10 ;
sum++ ;
}
if( sum % k == 0 )
return true ;
return false ;
}
bool pj( int n )
{
while( n > 0 )
{
if( n % 10 != 9 )
return false ;
n /= 10 ;
}
return true ;
}
int main()
{
cin >> t ;
for( int i = 1 ; i <= t ; i++ )
{
cin >> k >> n ;
if( kb( k , n ) && pj( n ) )
cout << "aya" << endl ;
else
cout << "baka" << endl ;
}
}