#P1740C. Bricks and Bags

    ID: 737 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>constructive algorithmsgamesgreedysortings*1400

Bricks and Bags

Description

There are nn bricks numbered from 11 to nn. Brick ii has a weight of aia_i.

Pak Chanek has 33 bags numbered from 11 to 33 that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.

After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let wjw_j be the weight of the brick Bu Dengklek takes from bag jj. The score is calculated as w1w2+w2w3|w_1 - w_2| + |w_2 - w_3|, where x|x| denotes the absolute value of xx.

It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?

Each test contains multiple test cases. The first line contains an integer tt (1t21041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The following lines contain the description of each test case.

The first line of each test case contains an integer nn (3n21053 \leq n \leq 2 \cdot 10^5) — the number of bricks.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — the weights of the bricks.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.

Input

Each test contains multiple test cases. The first line contains an integer tt (1t21041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The following lines contain the description of each test case.

The first line of each test case contains an integer nn (3n21053 \leq n \leq 2 \cdot 10^5) — the number of bricks.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — the weights of the bricks.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.

Sample Input 1

3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265

Sample Output 1

6
63
0

Note

In the first test case, one way of achieving a final score of 66 is to do the following:

  • Put bricks 11, 44, and 55 into bag 11.
  • Put brick 33 into bag 22.
  • Put brick 22 into bag 33.

If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:

  • Take brick 55 from bag 11.
  • Take brick 33 from bag 22.
  • Take brick 22 from bag 33.

The score is a5a3+a3a2=35+51=6|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.

It can be shown that there is no other distribution that results in a final score bigger than 66.