#C11949. Minimize Sum of Absolute Differences

    ID: 41321 Type: Default 1000ms 256MiB

Minimize Sum of Absolute Differences

Minimize Sum of Absolute Differences

You are given an array A of N integers. Your task is to rearrange the array in such a way that the sum of absolute differences between adjacent elements is minimized.

You are allowed to perform at most one swap operation. Among all possible rearrangements that achieve the minimal sum of absolute differences, you must output the lexicographically smallest array. If the array is already in its optimal state, then no swap operation is required.

Note: It turns out that simply sorting the array produces both the required optimal and lexicographically smallest arrangement.

Formula: The sum to minimize is \(\sum_{i=1}^{N-1} |A[i]-A[i-1]|\).

inputFormat

The first line contains an integer T, the number of test cases.

For each test case, the first line contains an integer N representing the number of elements in the array. The next line contains N space-separated integers, which are the elements of the array A.

outputFormat

For each test case, output a single line containing the lexicographically smallest rearrangement of the array that minimizes the sum of absolute differences between adjacent elements. The numbers should be separated by a single space.

## sample
3
3
3 1 2
4
4 1 3 2
5
1 2 3 4 5
1 2 3

1 2 3 4 1 2 3 4 5

</p>