Alice and Bob have an integer x consisting only of digits 2,3,5,7. They are playing a game with this number.
The rules of the game are as follows:
Note that when the number is reduced to one digit, it will always become a prime number, as it will be equal to one of 2,3,5 or 7.
Determine who wins the game if both play optimally.
Input:
Note:
Output:
For each test case:
Scoring:
In all test sets, 1≤t≤10.
In the first test set worth 35 points, 1≤x≤106.
In the second test set worth 50 points, 1≤x≤1012.
In the third test set worth 15 points, 1≤x≤1018.
In the first test, Alice starts with integer 3237 and can turn it into either 323 or 237, neither of which is a prime number.
Let's investigate first what happens if she choses to continue with number 323. Bob can then choose between either 32 or 23. As 23 is a prime which would make Bob lose instantly, he would choose 32. Then, however, Alice loses, as both 3 and 2 are primes, and she has no other turn.
What if Alice picks the other option at the start of the game, and removes the '3' from the beginning? Then Bob is left with number 237 and his situation is much worse. Whatever he chooses, he will end up with a prime right away - as both 23 and 37 are prime numbers.
Hence, Alice can win by removing the '3' from the beginning.