#K51092. Lexicographically Minimal Winning Move
Lexicographically Minimal Winning Move
Lexicographically Minimal Winning Move
You are given a string s representing the current state of a game. In each game, your objective is to remove a non-empty substring as your first move. However, to secure a win, you must remove the lexicographically smallest possible substring. It turns out that choosing the lexicographically smallest character in the string as the removal move is optimal.
Note: If the string contains only one character (i.e. \( |s| = 1 \)), then there is no valid winning strategy; in this case, output "NO".
You will be given several test cases. For each test case, determine the winning move using the strategy described above.
inputFormat
The input is read from standard input (stdin) and consists of multiple lines:
- The first line contains an integer \( t \) representing the number of test cases.
- Each of the next \( t \) lines contains a non-empty string \( s \).
Constraints: \( 1 \leq t \leq 10^5 \) and \( s \) contains only lowercase English letters.
outputFormat
For each test case, output one line to standard output (stdout) containing the lexicographically smallest substring that should be removed to win the game. If no winning strategy exists, output "NO".
## sample3
ba
abc
aabb
a
a
a
</p>