Alice and Bob is playing a game.
Each of them has a number. Alice’s number is A, and Bob’s number is B.
Each turn, one player can do one of the following actions on his own number:
Flip: Flip the number. Suppose X = 123456 and after flip, X = 654321
Divide. X = X/10. Attention all the numbers are integer. For example X=123456 , after this action X become 12345(but not 12345.6). 0/0=0.
Alice and Bob moves in turn, Alice moves first. Alice can only modify A, Bob can only modify B. If A=B after any player’s action, then Alice win. Otherwise the game keep going on!
Alice wants to win the game, but Bob will try his best to stop Alice.
Suppose Alice and Bob are clever enough, now Alice wants to know whether she can win the game in limited step or the game will never end.
Input
First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.
For each test case: Two number A and B. 0<=A,B<=10^100000.
Output
For each test case, if Alice can win the game, output “Alice”. Otherwise output “Bob”.
Sample Input
4
11111 1
1 11111
12345 54321
123 123
Sample Output
Alice
Bob
Alice
Alice
Hint
For the third sample, Alice flip his number and win the game.
For the last sample, A=B, so Alice win the game immediately even nobody take a move.
#include<cstring>
#include<cstdio>
typedef long long LL ;
const int MAXN = 100000+10 ;
const int MAXM = 1e5 ;
const int mod = 1e9+7 ;
int next[MAXN];
char a[MAXN],b[MAXN],s[MAXN];
void getnext(char *t,int m){
int i,j;i=j=0;
next[0]=-1;j=-1;
while(i<m){
if(j==-1||t[i]==t[j]) next[++i]=++j;
else j=next[j];
}
}
int Kmp(char *s,int n,char *t,int m){
int i,j;i=j=0;
while(i<n){
if(j==-1||s[i]==t[j]) {
++i;++j;
if(j==m) return i-m+1;
}else j=next[j];
}
return -1;
}
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%s %s",a,b);
int n=strlen(a); int m=strlen(b);
if(strcmp(b,"0")==0){ // 特判
puts("Alice");continue;
}
if(n<m) puts("Bob") ;//只要b是a的子串,alice一定赢
else {
int flag;
getnext(b,m);
flag=Kmp(a,n,b,m);
if(flag!=-1) puts("Alice");
else {
int l=n-1;
for(int i=0;i<n;i++) s[l--]=a[i];
flag=Kmp(s,n,b,m);
if(flag!=-1) puts("Alice");
else puts("Bob");
}
}
}
return 0;
}