FUNNUMS - FUN WITH LETTERS
Mr. Bean’s uncle gifted him 15 English letter toys from 'a' to 'o'. As Mr. Bean is a joker, no one was willing to play with him. So he sat on the floor and arranged these toys in ascending order i.e. “abcdefghijklmno”. Then he figured out the next greatest word in lexicographic order that can be formed by rearranging the toys is “abcdefghijklmon”. Now he is learning programming and wants to write a program to solve the following problem: Given all the words that can be formed by rearranging letters form the given word S, find the N-th greater word in lexicographic order. You can safely assume that such a word always exists.
The first line contains a natural number T denoting the number of test cases. Next T lines contain the description of T test cases, each with string S and value N.
For each test case print the answer in a separate line.
All letters in S are unique.
@Runtime error : description says "You can safely assume that such a word always exists.", so you should be able to determine by yourself the maximum n. I think it's part of the problem.
how big is n?