Given two points (x, y, floor), compute the walking distance: down from each floor, plus Manhattan street distance.
Easy2MathImplementationNo attempts yetTime limit2sMemory limit512 MBManhattan is laid out as a grid of streets, and very tall buildings stand all over the island.
Suppose you walk from your apartment at x=3, y=4, floor 3 to a friend's apartment at x=3, y=5, floor 2. The distance between the two points is the distance from your apartment down to the street, plus the distance along the streets to your friend's building, plus the distance from the street up to your friend's apartment.
The distance between two consecutive floors is 1. In Manhattan the street distance between two points is the absolute difference of the x coordinates plus the absolute difference of the y coordinates. Floor 0 means the point is already at street level.
For example, the distance from (3,4,3) to (3,5,2) is 3 for going down the first building, 0 for moving along x, 1 for moving along y, and 2 for going up the second building, so 3+0+1+2=6. More of that walk happens inside the buildings than on the streets.
When the start and the destination are the same point, you still ride down to the street and back up, so the distance is the sum of the two floor numbers.
Given two points, compute the distance in meters you have to walk.
The first line contains the number of test cases T.
Each of the next T lines contains six integers x1, y1, f1, x2, y2, f2 separated by spaces, describing two points. f1 is the floor of the first point and f2 is the floor of the second point.
1≤T≤100, 0≤x1,y1,f1,x2,y2,f2≤10000
For each test case, print the distance between the two points on its own line.