#P2953. Winning the Number Game
Winning the Number Game
Winning the Number Game
Bessie is playing a number game against Farmer John. The game is played as follows: In game \(i\), an integer \(N_i\) is given where \(1 \le N_i \le 1,000,000\). Bessie takes the first turn and then the two players alternate turns. In each turn, the current player subtracts from the number either the largest digit of the number or the smallest non-zero digit. For example, from the number 3014, one may subtract either \(1\) or \(4\) to obtain 3013 or 3010, respectively. The game terminates when the number becomes 0, and the last player to make a move is declared the winner.
If both players play optimally, determine the winner for each game. It is guaranteed that there are \(G\) games played with \(1 \le G \le 100\), and each game starts with a number \(N_i\) satisfying \(1 \le N_i \le 1,000,000\).
Example: Consider the game starting with \(N = 13\). Bessie can subtract \(3\) (the largest digit), leaving 10. Farmer John then subtracts \(1\) (the only valid move from 10) leaving 9. Bessie subtracts 9 and wins the game.
inputFormat
The first line contains a single integer \(G\), the number of games. Each of the following \(G\) lines contains a single integer \(N_i\), the starting number for the \(i^{th}\) game.
Constraints:
- \(1 \le G \le 100\)
- \(1 \le N_i \le 1,000,000\)
outputFormat
For each game, output a single line containing either Bessie
if Bessie wins, or Farmer John
if Farmer John wins, assuming both play optimally.
sample
4
13
14
30
10
Bessie
Bessie
Farmer John
Farmer John
</p>