G. Soft Memories
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Returning home and wrapping themselves in a warm blanket, Sunny and Aubrey pulled out a box of old photos. In total, they have $$$m$$$ photos. The $$$i$$$-th photo has an emotional tone $$$a_i$$$: some pictures are very quiet and peaceful, while others are bright, noisy, and joyful.

The friends want to arrange an evening of memories and view the photos according to a special system. To do this, they choose a number of photos $$$n$$$ ($$$1 \le n \le m$$$) that is a power of two, select any $$$n$$$ photos from the box, and arrange them in a row: $$$p_1, p_2, \dots, p_n$$$.

Then, a tournament of memories is held, consisting of $$$\log_2 n$$$ rounds:

  1. In the current round, the photos are divided into adjacent pairs.
  2. For each pair with photo tones $$$x$$$ and $$$y$$$, the friends gain $$$|x - y| - k$$$ resonance points, where $$$k$$$ is a fixed emotional cost per comparison.
  3. The photo with the larger tone $$$\max(x, y)$$$ advances to the next round (if $$$x = y$$$, either photo advances). The winners form a new row, preserving their relative order, after which the next round begins.

The process ends when a single photo remains. Help Sunny and Aubrey choose the number $$$n$$$, the photos themselves, and their initial order $$$p_1, p_2, \dots, p_n$$$ to maximize the total resonance over all rounds.

Input

Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $$$m$$$ and $$$k$$$ ($$$1 \le m \le 2 \cdot 10^5$$$, $$$0 \le k \le 10^9$$$) — the total number of photos and the cost per comparison.

The second line contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the emotional tones of the photos.

The sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, print a single integer — the maximum possible total resonance over the entire comparison process.

The answer may not fit into a 32-bit signed integer.

Example
Input
5
4 3
10 20 5 15
3 0
-5 0 5
1 4
-2
8 0
0 0 0 0 1 1 1 1
2 0
-1 -1
Output
16
10
0
4
0
Note

In the first test case use the order $$$20,5,15,10$$$. The first two pairs score $$$15-3=12$$$ and $$$5-3=2$$$. The final compares $$$20$$$ and $$$15$$$ for another $$$2$$$ points, giving $$$16$$$ in total.

In the second test case choose the photos with tones $$$-5$$$ and $$$5$$$. Their one comparison scores $$$10$$$.

In the third test case there is just one photo and no comparison, so the score is $$$0$$$.

In the fourth test case, pair each zero with a one in the first round. These four pairs score one point each. Only ones remain, so all later comparisons score zero. Each point requires a zero to lose, and there are only four zeros.