Suffix Operations

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Gildong has an interesting machine that has an array aa with nn integers. The machine supports two kinds of operations:

  1. Increase all elements of a suffix of the array by 11.
  2. Decrease all elements of a suffix of the array by 11.

A suffix is a subsegment (contiguous elements) of the array that contains a_na\_n. In other words, for all ii where a_ia\_i is included in the subsegment, all a_ja\_j’s where i<jni\lt j\le n must also be included in the subsegment.

Gildong wants to make all elements of aa equal --- he will always do so using the minimum number of operations necessary. To make his life even easier, before Gildong starts using the machine, you have the option of changing one of the integers in the array to any other integer. You are allowed to leave the array unchanged. You want to minimize the number of operations Gildong performs. With your help, what is the minimum number of operations Gildong will perform?

Note that even if you change one of the integers in the array, you should not count that as one of the operations because Gildong did not perform it.

입력

Each test contains one or more test cases. The first line contains the number of test cases tt (1t10001\le t\le 1000).

Each test case contains two lines. The first line of each test case consists of an integer nn (2n21052\le n\le 2\cdot 10^5) --- the number of elements of the array aa.

The second line of each test case contains nn integers. The ii-th integer is a_ia\_i (5108a_i5108-5\cdot 10^8\le a\_i\le 5\cdot 10^8).

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

출력

For each test case, print one integer --- the minimum number of operations Gildong has to perform in order to make all elements of the array equal.

힌트

In the first case, all elements of the array are already equal. Therefore, we do not change any integer and Gildong will perform zero operations.

In the second case, we can set a_3a\_3 to be 00, so that the array becomes \[1,0,0]\[-1,0,0]. Now Gildong can use the 22-nd operation once on the suffix starting at a_2a\_2, which means a_2a\_2 and a_3a\_3 are decreased by 11, making all elements of the array 1-1.

In the third case, we can set a_1a\_1 to 9696, so that the array becomes \[96,96,97,95]\[96,96,97,95]. Now Gildong needs to:

  • Use the 22-nd operation on the suffix starting at a_3a\_3 once, making the array \[96,96,96,94]\[96,96,96,94].
  • Use the 11-st operation on the suffix starting at a_4a\_4 22 times, making the array \[96,96,96,96]\[96,96,96,96].

In the fourth case, we can change the array into \[3,3,2,1]\[-3,-3,-2,1]. Now Gildong needs to:

  • Use the 22-nd operation on the suffix starting at a_4a\_4 33 times, making the array \[3,3,2,2]\[-3,-3,-2,-2].
  • Use the 22-nd operation on the suffix starting at a_3a\_3 once, making the array \[3,3,3,3]\[-3,-3,-3,-3].