#P10187. Palindromic Subtraction Game

    ID: 12179 Type: Default 1000ms 256MiB

Palindromic Subtraction Game

Palindromic Subtraction Game

Bessie and Elsie are playing a game with a pile of S stones. Initially, the pile contains S stones where \(1 \le S < 10^{10^5}\). The cows take turns subtracting stones from the pile with Bessie moving first. On her turn, a cow must remove \(x\) stones from the pile, where \(x\) is any positive palindromic integer. A palindromic number is defined as a positive integer that reads the same forward and backward (with no leading zeros); examples include \(1\), \(121\), and \(9009\). Note that numbers like \(990\) (which would have a leading zero when reversed) are not palindromic.

If a cow starts her turn with an empty pile, she loses the game. There are \(T\) test cases (\(1 \le T \le 10\)). For each test case, determine who wins the game if both cows play optimally.

Hint: Notice that 1 is always a valid move. In fact, if \(S \bmod 10 \neq 0\), Bessie can subtract \(S \bmod 10\) (which is a single-digit, and hence palindromic) to leave a multiple of 10. If \(S\) is a multiple of 10, any move will leave a non-multiple of 10, giving Elsie the winning strategy.

inputFormat

The first line of input contains a single integer \(T\) denoting the number of test cases. Each of the following \(T\) lines contains one integer \(S\), given as a string due to its potentially enormous size (\(1 \le S < 10^{10^5}\)).

outputFormat

For each test case, output a single line containing either Bessie if Bessie wins the game under optimal play, or Elsie otherwise.

sample

5
1
10
12
20
100
Bessie

Elsie Bessie Elsie Elsie

</p>