

The first and the last number of the array are adjacent to each other.
The given array is {3, 6, 8, 4, 5}. So you have to consider all the permutations of this array like one of the permutations of this array is {6, 3, 5, 4, 8}. For this permutation answer will be sum of absolute difference of adjacent elements that is maxSum = |6-3| + |3-5| + |5-4| + |4-8| + |8-6| = 12 and for another permutation, say {3, 8, 4, 6, 5}, maxSum = |3-8| + |8-4| + |4-6| + |6-5| + |5-3| = 14. In this case, it will be the maximum of all permutations. So the answer will be 14.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains a single integer ‘N’ denoting the length of the array.
The second line of each test contains N space-separated integers representing the elements of the given array.
For each test case, in a separate line, print the maximum sum of the absolute difference of any permutation of the given array.
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10000
1 <= arr[I] <= 10^6
where ‘T’ is the total number of test cases, N is the length of the array and arr[I] is the value at index ‘I’ of the array.
The idea is to keep the difference between any two adjacent numbers maximum. This can be achieved if we put small and large elements alternatively.