A natural number A is given. Among all numbers that can be made by using exactly the same digits as A with the same multiplicities, the next number of A is the smallest number that is greater than A.
Two numbers have the same composition when each digit from 0 through 9 appears the same number of times in both numbers. For example, 123 and 321 have the same composition because the digits 1, 2, and 3 each appear once. Likewise, 14232 and 12243 have the same composition, but 14232 and 14432 do not.
For each test case, find the next number of A.
The first line contains the number of test cases T. (1 <= T <= 1,000)
Each of the next T lines contains one natural number A. A has at most 80 digits.
For each test case, output the next number of A on its own line. If no next number exists, output BIGGEST.