## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Bricks and Bags Codeforces Solution

C. Bricks and Bags
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of ${a}_{i}$.

Pak Chanek has $3$ bags numbered from $1$ to $3$ 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 ${w}_{j}$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|{w}_{1}-{w}_{2}|+|{w}_{2}-{w}_{3}|$, where $|x|$ denotes the absolute value of $x$.

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?

Input

Each test contains multiple test cases. The first line contains an integer $t$ ($1\le t\le 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 $n$ ($3\le n\le 2\cdot {10}^{5}$) — the number of bricks.

The second line of each test case contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le {10}^{9}$) — the weights of the bricks.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\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.

Note

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

• Put bricks $1$$4$, and $5$ into bag $1$.
• Put brick $3$ into bag $2$.
• Put brick $2$ into bag $3$.

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

• Take brick $5$ from bag $1$.
• Take brick $3$ from bag $2$.
• Take brick $2$ from bag $3$.

The score is $|{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 $6$.