Crazy Subsequences
Problem
Chef has a binary string . He can modify it by choosing any subsequence of length from it and deleting the first and last character of the subsequence.
For example, if , Chef can choose the subsequence marked in red and delete its first and last characters, obtaining the string .
Chef wonders what is the lexicographically largest string he can obtain by modifying the original string using a finite number of operations. Please help Chef in this task.
Note: A binary string is said to be lexicographically larger than another binary string if:
- is a proper prefix of (for example, is lexicographically larger than ); or
- There exists an index such that and .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of a single line of input containing the original binary string .
Output Format
For each test case, output on a new line the lexicographically largest string Chef can obtain.
Constraints
- is a binary string, i.e, only contains the characters and in it
- The sum of over all test cases won't exceed .
Sample 1:
4 101 1010 0000 0001
101 11 0000 01
Explanation:
Test case : It is optimal to not perform any moves.
Test case : In one move, by choosing the subsequence , the string can be made into , which is the lexicographically largest possible.
Test case : It is optimal to not perform any move.
Comments
Post a Comment