

Example:-
INPUT : M = 123 , K = 1
OUTPUT: 312
In the above example, K = 1, hence only 1 swap operation is available.
Operation 1: Swap 1 with 3 so the integer becomes 312
INPUT : M = 567392 , K = 3
OUTPUT: 976532
In the above example, K = 3, hence a maximum of 3 swap operation available
Operation 1: Swap 5 with 9 so the integer becomes 967352
Operation 2: Swap 6 with 7 so the integer becomes 976352
Operation 3: Swap 3 with 5 so the integer becomes 976532
INPUT : M = 751, K = 2
OUTPUT: 751
In the above example, No swaps are required as it is already the maximum possible integer with that set of digits.
INPUT : M = 3849 , K = 0
OUTPUT: 3849
In the above example, K = 0, hence no swap operations are available.
The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.
The first line of each test case contains a string M, denoting the input integer in the form of string.
The second line of each test case contains a single integer K, denoting the maximum number of swap operations allowed.
For every test case, print a single string which is the maximum integer formed after doing at most K swaps.
The output of every test case will be printed in a separate line.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= | M | <= 20
0 <= K <= 10
Time limit: 1 second
We can take one digit at a time and swap it with its following digits forming a new integer each time. If the new integer formed is the new maximum integer, we update it. We repeat this process K times.
In our previous approach, we take one digit at a time and swap it with its following digits. But it is clearly visible that to form the maximum integer, only the maximum digit is swapped at the front. So instead of trying all the swappable pairs, we swap the current digit with the maximum digit in the string which is not yet swapped to the front. Finding the maximum digit before the recursive call will save us a lot of unnecessary swaps.