시간 제한
메모리 제한
Given an integer A, only other integers that are permutations of A are useful. All other numbers are useless. Find the next largest integer B, where the digits in B is a permutation of the digits of A. For example, suppose A=2413, then the next largest permutation is 2431. If A is already the largest permutation, output “USELESS”.
The first line in the data file is an integer that represents the number of data sets to follow. Each line is a single integer A (A <= 2,000,000).
Print B, the next largest permutation. If it doesn’t exist print “USELESS”.