#t2. 魔法快递
魔法快递
Magic Delivery
Problem Description
The courier of the magic academy, little Y, has earned the title of "Best Magic Courier". But the dean dislikes him, so he gives him a very difficult task. The dean gives him the coordinates of magic nodes; he must deliver the magic packages to these nodes. He will make the deliveries in the following way:
- The magic package is crafted at point , and little Y starts delivering from this point.
- He may move from to any one of the three points , , or .
- After delivering all the packages, he must return to the academy, i.e. return to .
Each move takes exactly one second, and delivering a package takes no time ( seconds). The dean wants the delivery to be as fast as possible. You need to compute the minimum time to finish delivering all the magic packages. It is guaranteed that all nodes can be visited.
Input Format
Each test contains several test cases. The first line contains an integer () — the number of test cases. This is followed by the description of each test case.
The first line of each test case contains five integers , , , , (, ), the number of magic nodes to deliver and the coordinates of the start and end points.
The second line contains integers ().
The third line contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one integer on its own line: the minimum time to finish delivering all the magic packages.
Sample Input #1
4
1 2 3 5 2
4
4
3 1 3 5 2
3 4 3
5 4 1
6 1 2 7 3
5 2 3 5 5 3
6 4 3 1 4 1
5 6 9 8 6
7 7 7 7 7
3 1 8 8 3
Sample Output #1
6
13
19
15
Explanation / Hint
Take the second test case as an example:
- Moving from to takes seconds.
- Moving from to takes seconds.
- Moving from to takes seconds.
- Moving from to takes seconds.
The total time is seconds. It can be proven that no faster delivery is possible.