Problem: You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers.
Consider a number axis. The capital of your empire is initially at . There are unconquered kingdoms at positions . You want to conquer all other kingdoms.
There are two actions available to you:
- You can change the location of your capital (let its current position be ) to any other conquered kingdom (let its position be ) at a cost of .
- From the current capital (let its current position be ) you can conquer an unconquered kingdom (let its position be ) at a cost of . You cannot conquer a kingdom if there is an unconquered kingdom between the target and your capital.
Note that you cannot place the capital at a point without a kingdom. In other words, at any point, your capital can only be at or one of . Also note that conquering a kingdom does not change the position of your capital.
Find the minimum total cost to conquer all kingdoms. Your capital can be anywhere at the end.
Input Format: The first line contains a single integer () — the number of test cases. The description of each test case follows.
The first line of each test case contains integers , , and (; ).
The second line of each test case contains integers ().
The sum of over all test cases does not exceed .
Output Format: For each test case, output a single integer — the minimum cost to conquer all kingdoms.
Note: Here is an optimal sequence of moves for the second test case:
- Conquer the kingdom at position with cost .
- Move the capital to the kingdom at position with cost .
- Conquer the kingdom at position with cost .
- Move the capital to the kingdom at position with cost .
- Conquer the kingdom at position with cost .
- Conquer the kingdom at position with cost .
- Conquer the kingdom at position with cost .
The total cost is . You cannot get a lower cost than this.