Palindrome Game

시간 제한2초메모리 제한1024 MB

요약
S개의 돌 더미에서 두 사람이 번갈아 양의 정수 회문만큼 돌을 가져가며, 빈 더미를 마주한 사람이 지는 게임에서 승자를 판정한다.
난이도

보통10점 중 6점

유형
게임 이론, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

Bessie and Elsie are playing a game with a pile of stones that initially contains SS stones (1≤S<101051\le S<10^{10^5}). The two cows alternate turns, with Bessie going first. When it is a cow's turn, she must remove xx stones from the pile, where xx is any positive integer palindrome of the cow's choosing. If the pile is empty when a cow's turn starts, that cow loses.

Definition: A positive integer is a palindrome if it reads the same forward and backward; examples of palindromes include 1, 121, and 9009. Leading zeros are not allowed; e.g., 990 is *not* a palindrome.

There are TT (1≤T≤101\le T\le 10) independent test cases. For each test case, print who wins the game if both cows play optimally.

입력

The first line contains TT, the number of test cases. The next TT lines describe the test cases, one line per test case.

Each test case is specified by a single integer SS.

출력

For each test case, output B if Bessie wins the game under optimal play starting with a pile of stones of size SS, or E otherwise, on a new line.

예제1

  1. 예제 1

    입력
    3
    8
    10
    12
    
    예상 출력
    B
    E
    B