// Arup Guha
// 1/16/2013
// Solution to 2009 Greater NY Regional Problem E: The Next Permutation

import java.util.*;

public class e {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			int dummy = stdin.nextInt();
			char[] num = stdin.next().toCharArray();

			// Execute next permutation, if possible.
			boolean result = nextPerm(num);

			// Output result.
			if (!result) {
				System.out.println(loop+" BIGGEST");
			}
			else
				System.out.println(loop+" "+new String(num));
		}

	}

	public static boolean nextPerm(char[] num) {

		// Count to last slot with increasing contiguous digits, from back.
		int i = num.length - 1;
		while (i >= 1 && num[i-1] >= num[i]) i--;

		// Fail case, no pair found.
		if (i == 0) return false;

		// Find item to swap with.
		int j = i;
		i--;
		while (j < num.length && num[i] < num[j]) j++;
		j--;

		// Swap.
		char temp = num[i];
		num[i] = num[j];
		num[j] = temp;

		int start, end;

		// Reverse rest of the list.
		for (start = i+1, end = num.length-1; start<end; start++,end--) {
			temp = num[start];
			num[start] = num[end];
			num[end] = temp;
		}

		return true;
	}

}