#P1547A. Shortest Path with Obstacle
Shortest Path with Obstacle
No submission language available for this problem.
Description
There are three cells on an infinite 2-dimensional grid, labeled , , and . Find the length of the shortest path from to if:
- in one move you can go to any of the four adjacent cells sharing a side;
- visiting the cell is forbidden (it is an obstacle).
The first line contains an integer () — the number of test cases in the input. Then test cases follow. Before each test case, there is an empty line.
Each test case contains three lines. The first one contains two integers () — coordinates of the start cell . The second one contains two integers () — coordinates of the finish cell . The third one contains two integers () — coordinates of the forbidden cell . All cells are distinct.
Coordinate corresponds to the column number and coordinate corresponds to the row number (see the pictures below).
Output lines. The -th line should contain the answer for the -th test case: the length of the shortest path from the cell to the cell if the cell is not allowed to be visited.
Input
The first line contains an integer () — the number of test cases in the input. Then test cases follow. Before each test case, there is an empty line.
Each test case contains three lines. The first one contains two integers () — coordinates of the start cell . The second one contains two integers () — coordinates of the finish cell . The third one contains two integers () — coordinates of the forbidden cell . All cells are distinct.
Coordinate corresponds to the column number and coordinate corresponds to the row number (see the pictures below).
Output
Output lines. The -th line should contain the answer for the -th test case: the length of the shortest path from the cell to the cell if the cell is not allowed to be visited.
Samples
Note

