import java.util.*;
import java.io.*; 

public class Main 
{ 
	static void SwapInts(int array[], 
						int position1, 
						int position2) 
	{ 
 
		int temp = array[position1]; 

		array[position1] = array[position2]; 
		

		array[position2] = temp; 
	} 
	

	static void KSwapMaximum(int []arr, 
							int n, int k) 
	{ 
		for (int i = 0; 
				i < n - 1 && k > 0; ++i) 
		{ 
	

			int indexPosition = i; 
			for (int j = i + 1; j < n; ++j) 
			{ 
	

				if (k <= j - i) 
					break; 
	

				if (arr[j] > arr[indexPosition]) 
					indexPosition = j; 
			} 
	

			for (int j = indexPosition; j > i; --j) 
				SwapInts(arr, j, j - 1); 
	

			k -= indexPosition - i; 
		} 
	} 
	
	// Driver code 
	public static void main(String args[]) 
	{ 
        Scanner sc= new Scanner(System.in);
        int z= sc.nextInt();
        for (int i=0;i<z;i++){
            
            int n = sc.nextInt();
            int arr[] = new int[n];
            for (int j=0;j<n;j++){
                arr[j]=sc.nextInt();
            }
            int k = 3; 
	
            KSwapMaximum(arr, n, k); 
        
		// Print the final Array 
            for (int v = 0; v < n; ++v) 
                System.out.print(arr[v] + " "); 
        }
}
} 

