Given two numbers N and M. Construct maximal number by permuting (changing order) the digits of N, not exceeding M. It is allowed to leave N as it is.
The first line of the input contains T i.e number of test cases. Each line of the test case contains Two numbers N, M separated by space.
Each new line of the output contains only one single integer i.e Maximize Permutation if possible else -1.
Tese Case 1: here are total 3! permutations possible for N = 123, But the only permutation that satisfies the given condition is 213.
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.