Given a non-negative number n and a value k. Find the k-th smallest number that can be formed using the digits of the given number n. It is guaranteed that the k-th smallest number can be formed. Note that the number could be very large and may not even fit into long long int.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains the integer n.
The second line of each test case contains the integer k.
Output:
Print the k-th smallest number that can be formed using the digits of the number n for each test case in a new line.
Constraints:
1<= T <=100
1<= N <=101000
1<= K <=10
Example:
Input:
2
1234
2
36012679802
5
Output:
1243
10022366897
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.
preparecodinginterview_dot_com | 190 |
__murugan__ | 173 |
manvimahajan20 | 140 |
xiaoyan_yunche | 139 |
ShameekAgarwal | 116 |
preparecodinginterview_dot_com | 190 |
__murugan__ | 173 |
manvimahajan20 | 166 |
SoumyaKaushik | 146 |
arpit_anshuman | 140 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |