CF2179B.Blackslex and Showering

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Blackslex and Showering

After his IMO medalist friend showered for two hours so that "he doesn't have to shower this again this week," Blackslex will be late for class!

In order to get to class, Blackslex must take the crowded elevator to many floors in a certain order. Because he is a hacker, he can skip visiting up to one floor without the other people knowing. His time taken is the sum of the absolute differences between consecutive floor numbers. Find the minimum time taken, given that he can skip up to one floor.

More formally, given an array a=[a1,a2,,an]a = [a_1, a_2, \ldots, a_n] of nn integers, you can choose up to one index k{1,2,,n}k \in \{1, 2, \ldots, n\} to erase such that the sum $$ um_{i=1}^{n-2} |b_i - b_{i+1}|$$is minimized, where$b = [a\_1, \ldots, a\_{k-1}, a\_{k+1}, \ldots, a\_n]$is the array after erasing elementa_ka\_k. Report the minimum sum.

Input

The first line contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains one integer nn (3n21053 \le n \le 2 \cdot 10^5) — the size of the array.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1001 \le a_i \le 100).

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

Output

For each test case, output a single real number — the minimum time taken.

Note

For the first test case, one optimal index to remove from [4,15,1,7,9][4, 15, 1, 7, 9] is k=2k = 2. The array becomes [4,1,7,9][4, 1, 7, 9] and the time taken is 1111. For the second test case, the optimal index to remove is k=3k = 3.

Samples

3
5
4 15 1 7 9
3
2 4 8
6
11 13 17 19 23 29
11
2
12

在线编程 IDE

建议全屏模式获得最佳体验