#K61612. Lexicographically Smallest String

    ID: 31349 Type: Default 1000ms 256MiB

Lexicographically Smallest String

Lexicographically Smallest String

Given a string S, remove exactly one character from S to produce a new string such that the resulting string is the lexicographically smallest among all possible outcomes. In other words, for a string \(S\) of length \(N\), you need to choose an index \(i\) (\(0 \leq i < N\)) to remove the character \(S_i\) and then compare all resulting strings to determine the smallest in lexicographical order.

Note: A string \(A\) is lexicographically smaller than string \(B\) if in the first position where they differ, the character in \(A\) comes before the character in \(B\) in the English alphabet. If one string is a prefix of the other, the shorter string is considered smaller.

You are required to process multiple test cases from standard input and output the results to standard output.

inputFormat

The first line contains an integer \(T\), denoting the number of test cases. Each of the following \(T\) lines contains a single string \(S\).

For example:

4
abcdef
xyz
cba
aabbcc

outputFormat

For each test case, output the lexicographically smallest string obtainable by removing exactly one character from the given string, each on a separate line.

For example, the output corresponding to the above sample input is:

abcde
xy
ba
aabbc
## sample
4
abcdef
xyz
cba
aabbcc
abcde

xy ba aabbc

</p>