Three Three Three
Time limit1sMemory limit2048 MB
Players alternately erase the middle digit of three consecutive digits that form a multiple of 3; find the winner under optimal play.
- Level
Medium6 of 10
- Topics
- Game theory, Math, String
- Solved
- No attempts yet
Problem
Two players, Anda and Kamu, want to play a game. Initially, there is an integer that consists of only non-zero digits. Anda and Kamu take turns, starting with Anda.
On a turn, the player must do the following. First, choose three consecutive digits in such that, read as a three-digit integer, they are divisible by . Then erase the middle digit and concatenate the remaining two digits, so the number of digits in decreases by one.
If the player to move has no valid move, that player loses. Assuming both players play optimally, determine the winner.
Input
This problem has multiple test cases. The first line contains an integer (), the number of test cases.
Each test case is a single line containing an integer (). consists only of non-zero digits.
The sum of the number of digits of over all test cases does not exceed .
Output
For each test case, print one line with the winner if both players play optimally. If Anda, the first player, wins, print Anda. Otherwise, print Kamu.