Public submissions
Source code of every submission to this problem in this contest will be visible for everyone since 2013-03-14 06:00:00.
Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

NEXT - The Next Permutation

 

For this problem, you will write a program that takes a (possibly long) string of decimal digits, and 
outputs the permutation of those decimal digits that has the next larger value (as a decimal number) 
than the input number. For example: 
123 -> 132 
279134399742 -> 279134423799 
It is possible that no permutation of the input digits has a larger value. For example, 987.

For this problem, you will write a program that takes a (possibly long) string of decimal digits, and outputs the permutation of those decimal digits that has the next larger value (as a decimal number) than the input number. For example: 

123 -> 132

279134399742 -> 279134423799 

It is possible that no permutation of the input digits has a larger value. For example, 987.

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set is a single line that contains the data set number, followed by a space, followed by up to 80 decimal digits which is the input value.

Output

For each data set there is one line of output. If there is no larger permutation of the input digits, the output should be the data set number followed by a single space, followed by the string BIGGEST. If there is a solution, the output should be the data set number, a single space and the next larger permutation of the input digits. 

Example

Input:
3 
1 123 
2 279134399742 
3 987 

Output:
1 132 
2 279134423799 
3 BIGGEST 

Added by:Fabio Avellaneda
Date:2013-03-11
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C C++ 4.3.2 CPP JAVA
Public source code since: 2013-03-14 06:00:00

hide comments
2018-02-15 21:49:33
Why does it keep saying "wrong problem" when I submit my solution!! :(
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.