
String ‘p’ is lexicographically smaller than string ‘q’, if ‘p’ is a prefix of ‘q’, is not equal to ‘q’ or there exists ‘i’, such that ‘p[i]’ < ’q[i]’ and for all ‘j’ < ’i’ it is satisfied that ‘p[j]’ = ’q[j]’.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain two space-separated integers ‘N’ and ‘K’ which denotes the length of ‘S’ and integer ‘K’.
The second line of each test case will contain a single string ‘S’.
For each test case, return the lexicographically smallest string obtained by performing any number of operations on ‘S’.
You don’t need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^3
1<= K <= N
S[ i ] belongs to {a to z}
Time limit: 1 sec
For the value of the ‘K’ > 1 it is possible to obtain any permutation of the string ‘S’. Considering two characters at index ‘i’ and ‘i + 1’ we will prove that it is possible to swap them.
After this operation, two characters are swapped.
This way by swapping any two consecutive characters we can obtain any permutation.
For ‘K’ = 1, after any number of operations, we will get one of its circular rotations.
Eg for “abcd” : “abcd”, “bcda”, “cdab”, “dabc” are possible.
We will compare all the circular rotations and pick the smallest of all as our answer.