A strongest string
88% Success1512 Attempts20 Points1s Time Limit256MB Memory1024 KB Max Code

You are given a string \(S\) that consists of \(N\) lowercase letters of the Latin alphabet.
In one step, you can remove any letter in the string. You are required to determine the maximum lexicographic sentence of words you can leave so that all letters are different.

The lexicographical order on the set of all these finite words orders the words in the following manner:

  1. You are given two different words of the same length, for example, \(a = a_1,\ a_2,\ ..., a_k\) and \(b = b_1,\ b_2,\ ...,\ b_k\). The order of these two words depends on the alphabetic order of the symbols on the first place \(i\) where the two words are different (counting from the beginning of the words), \(a < b\) if and only if \(a_i < b_i\) in the underlying order of alphabet \(A\).
  2. If two words have different lengths, then the usual lexicographical order pads the shorter one with 'blanks' (a special symbol that is treated as smaller than every element of \(A\)) until the words are made of the same length. Now, the words are compared as in the previous case.

Input format

  • The first line contains \(T\) denoting the number of test cases.
  • The first line of each test case contains \(N\) denoting the length of string \(S\).
  • The second line of each test case contains string \(S\).

Output format

For each test case, print the answer.

Constraints

\(1 ≤ T ≤ 10\)
\(1 ≤ N ≤ 10^5\)
\(|S| = N\)

Examples
Input
2
4
aybc
3
zzz
Output
yc
z
Explanation

For the first string, the answer is "yc" because "yc" > "ybd", "yc" > "y", "yc" > "yd", "y" > "a", "y" > "b" and "y" > "c".

For the second string, the answer is "z" because strings "zz" and "zzz" have the same letters.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...
Results