#P11768. 破自行车
破自行车
Description
The city where Tianyi lives is like an infinitely large Manhattan. If we place the city map on a Cartesian coordinate system, any integer point represents an intersection. Tianyi's doorstep intersection is at , and she needs to start from here and reach the intersection of the studio as soon as possible. Every minute, Tianyi can move from her current intersection to , , , or .
But why would Tianyi walk to work? She has a very fast and mysterious broken bicycle! With it, Tianyi can instantly charge from to any one of the four positions , , , , without spending any time. However, to prevent the broken bicycle from falling apart, Tianyi can only use it up to times.
So, with the help of the broken bicycle, what is the minimum time Tianyi needs to travel from to ?
Due to the frequent moving of the studio, there are multiple test cases.
Input Format
The first line of the input contains an integer — the number of test cases.
The only line of each test case contains four intergers — the x,y coordinates of the intersection where the studio is located, the usage limit of the bicycle, and the charging distance of the bicycle.
Output Format
For each test case, output a single integer — the minimum time Tianyi needs to travel from to .
3
4 5 3 2
1 1 4 5
8 8 4 8
3
2
0
Hint
Sample Explanation
We use to represent charging, and to represent walking.
For the first test case, a possible moving way is: .
For the second test case, a possible moving way is: .
For the third test case, a possible moving way is: .
Constraints
Subtasks applied. You can only gain the score of the subtask if you accepted all the tests in the subtask.
| Subtask ID | Special Property | Score | |||
|---|---|---|---|---|---|
For all tests, it is guaranteed that ,.
京公网安备 11011102002149号