# include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> LL;
typedef vector<ii> vii;
typedef vector<LL> vLL;
# define FAST ios_base::sync_with_stdio(false);cin.tie(0);
# define mp(x,y) make_pair(x,y)
# define F first
# define S second
# define sii(p) sd(p.F),sd(p.S)
# define sLL(p) sll(p.F),sll(p.S)
# define stl(x) x.begin(),x.end()
# define stlr(x) x.rbegin(),x.rend()
# define rep(i,a,b) for(auto i = a; i < b; ++i)
# define rrep(i,a,b) for(auto i = a; i > b ;--i)
# define repstr(str,i) for(auto i = 0 ; str[i] ;++i)
# define repstl(stl,l) for(auto l : stl)
# define gets(str) scanf("%s",str)
# define gc() getchar()
# define pc(c) putchar(c)
# define nline pc('\n')
# define pd(x) printf("%d",x)
# define pll(x) printf("%lld",x)
void sd(int &n){
n = 0;
int sign = +1;
char ch;
while(isspace(ch = gc()));
if(isdigit(ch))
n = ch - '0';
else
sign = ch == '+' ? +1 : -1;
while(isdigit(ch = gc()))
n = (n << 3) + (n << 1) + ch - '0';
n *= sign;
}
# define pMAT(mat,r,c) rep(i,0,r){\
rep(j,0,c)\
pd(mat[i][j]),pc(' ');\
nline;\
}
# define TC int tc;sd(tc);while(tc--)
// ACTUAL CODE-------------------------------------------------------
/*
IDEA
bool DP[MOVES[NUMS];
DP[i][j] => ith move and jth number, contains the answer to question
what will happen to the one whose move is this ?
Will he win? or lose?
1 - win
0 - loose
1. TRANS[num] = { , , , };
TRANS contains the possible list of numbers
which can be obtained if a move is made at that number.
2. If the total no. of moves are odd, ADA will play move no. 1,3,5,...
Else ADA will play move no. 2,4,6,..
3. For the first move,
DP[1][num]
if it's ADA's move (i.e. total no. of moves are ODD),
for this entry to be true, there must exist atleast one transition leading to
a number which is greater than current number num.
if it's VINIT's move (i.e. total no. of moves are even)
for this entry to be true, there must be atleast one transition to a number
which is smaller than current number num.
4. for 2nd move onwards,
every player will keep their entry true, if there is atleast one
transition that leads to loose for the opponent.
*/
# define NUM 10000
int TRANS[NUM+1][4];
// Fill transition entries, for every number
void fillTrans(void){
rep(i,0,NUM){
int ptr = 0;
char digit[4];
int num = i;
rrep(i,3,-1){
digit[3-i] = num%10;
num /= 10;
}
num = i;
rep(i,0,4){
char ch = digit[i];
(digit[i] += 1) %= 10;
int n = digit[3];
rrep(i,2,-1)
n = (n*10)+digit[i];
TRANS[num][ptr++] = n;
digit[i] = ch;
}
}
}
void printTrans(int num){
cout << num << endl;
cout<<TRANS[num][0]<<" "<<TRANS[num][1]<<" "<<TRANS[num][2]<<" "<<TRANS[num][3]<<endl;
}
# define MOVES 100
bool DP[MOVES+1][NUM];
int main(void){
fillTrans();
TC{
int num,moves;
sd(num);
sd(moves);
// initialize
rep(i,0,moves+1)
rep(j,0,NUM)
DP[i][j] = 0;
// base case
rep(i,num+1,NUM)
DP[0][i] = true;
// for first move
// ADA
if(moves&1)
rep(j,0,NUM){
rep(i,0,4)
DP[1][j] |= (TRANS[j][i] > j);
}
// VINIT
else
rep(j,0,NUM){
rep(i,0,4)
DP[1][j] |= (TRANS[j][i] < j);
}
// for all further moves, there must be
// at least one transisiton, where
// the opponent will loose !!
rep(i,2,moves+1)
rep(j,0,NUM){
rep(k,0,4)
DP[i][j] |= !DP[i-1][TRANS[j][k]];
}
puts(DP[moves][num]?"ADA":"VINIT");
nline;
}
return 0;
}
/*
Correct Output :
Ada
Ada
Vinit
Ada
Vinit
Ada
Vinit
Vinit
Ada
Vinit
*/
IyBpbmNsdWRlPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgCQkJbGw7CnR5cGVkZWYgcGFpcjxpbnQsaW50PgkJaWk7CnR5cGVkZWYgcGFpcjxsbCxsbD4JCQlMTDsKdHlwZWRlZiB2ZWN0b3I8aWk+CQkJdmlpOwp0eXBlZGVmIHZlY3RvcjxMTD4JCQl2TEw7CgojIGRlZmluZSBGQVNUCQkJCWlvc19iYXNlOjpze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