You have been given a String
For example , the word
Now, you need to find all the disitnct anagrams of String
Can you do it ?
INPUT:
The first line of input contains the number of test cases denoted by T. The next T lines of input contain a string S and a number N.
OUTPUT:
You need to find and print the anagram of the given string which occurs at the $$N^{th} position when they are arranged in lexicographical order.
Constraints:
4 bcda 20 cbad 5 ydvtrs 268 asfda 32
dacb adbc srdvyt dfasa
For case 2, one need to find the anagram of "cbad" which occurs at 5th place when arranged in lexicographical order.
The anagrams that occur at the first four positions are abcd, abdc, acbd and acdb respectively. The fifth anagram is adbc.
Please login to use the editor
You need to be logged in to access the code editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor