
If βSβ is a regular sequence, then (S) is also regular.
If βAβ and βBβ represent two regular sequences, then their concatenation βABβ is also regular.
Therefore, the sequences (), ()() and (())() are regular, while ()(, ) and ))() are non-regular.
β(β is considered lexicographically smaller than β)β.
Two subsequences are distinct if they differ at least at one of the indexes. E.g. β))β and β((β are distinct whereas β((β and β((β are not.
N = 5
S = ()
K = 2
Explanation :
All possible subsequences of the given sequence are : β(β , β)β and β()β.
The non-regular subsequences among these are : β(β and β)β.
Of these the lexicographically β2ndβ subsequence is β)β.
Hence, final result = β)β.
The first line contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.
The first line of each test case contains two integers βNβ and βKβ.
The second line of each test case contains a string βSβ of length βNβ.
For each test case, print a string denoting the lexicographically βKthβ non-regular subsequence of string βSβ.
Print the output of each test case in a new line.
You donβt need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1β<= N <= 10^5
1 <= K <= 10^9
S[i] = β(β or S[i] = β)β.
Time Limit : 1 sec
Algorithm :
Approach :
Algorithm :