Smallest String

3.3

11 votes
Problem

You will be given a string S contains only lower case alphabets. You areallowed to remove any character from the string and can place anywhere in the string. You have to print lexicographically smallest string that can be formed by making above operation only one time.

Input :

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case contains the single integer N denoting length of string S.

The second line contains the string S.

Output :

For each test case, output a single line containing the answer to the corresponding test case.

Constraints :

1<=T<=50

1<=N<=50

S will consist of only lowercase English letters.

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

Example case 1. The optimal solution here is to choose the last character and put it in the beginning of the string. So the answer will be adcb

Example case 2. The optimal solution here is to choose the 5-th character (1-based index) and put it between the 2-nd and the 3-rd characters. So the answer will be xyyzzzz

Editor Image

?