Statement
A farm has rows and columns. There is one crop in each of distinct cells. The -th crop is in row and column .
A harvesting machine occupies a consecutive segment of rows in one column. Initially, it occupies only the cell in row and column . That cell has no crop.
You may perform either of these operations:
- Extend: Add one cell to the top or bottom end of the machine.
- Move: Shift every cell occupied by the machine one column to the left or right.
After an operation, every crop in a cell occupied by the machine is harvested immediately. No part of the machine may leave the farm during an operation.
Find the minimum number of operations needed to harvest every crop.
Input
The input is given in the following format:
Each case is given in the following format:
is the number of test cases. Each case gives the farm dimensions, the machine’s initial cell, the number of crops, and the position of each crop.
Output
For each test case, print the minimum number of operations on one line.
Constraints
- .
- , , .
- , .
- .
- , ().
- There is no crop in the machine’s initial cell.
- All crop positions are distinct.
- The sum of over all test cases is at most .
Subtasks
Samples
In the first case, two extensions and three moves to the right harvest every crop. In the second case, one extension and two moves to the left are needed.