spoj#PERFECTR. Perfect Road
Perfect Road
Byteland is a ficticious city commonly mentioned here on SPOJ.
An ancient legend tells that bytelandians lived in a simple town, just like the Old Western California, where there was just a single straight road of about 500 Meters and all houses, bars and hotel had the road in front of them. In Byteland, although there is a small difference, here, including the Main Road, each house has its own road that connects to the main road, but according to the law, each particular road need to be perpendicular to the main road.
So their world can be abstracted as a two-dimensional grid with integer coordinates. The main road is the x-axis and houses are points connected perpendicularly to the x-axis (in both the positive and negative y directions).
In this particular city, if a person A needs to visit any other person B, he needs to walk along the street that connects his home to the main road until it reaches the main road, then walk through the main road up to the street that comes from the other home, and then walk this street to B's home. But in the case their homes are in the same street, they only need to walk the segment that connects their houses.
The distance between two persons home is defined as:
1)If two homes have the same 'x' coordinate. The distance between them is the absolute difference between their 'y' coordinates. (this is the case where they live in the same street)
2)Otherwise, the distance is the distance between Person A and the main road + the distance between Person B and the main road + the absolute difference between their 'x' coordinates.
Here are 3 persons, one at (1,1), other at (1,4), and the last one at (4,1). This is the first example.
|
||||
The government is about to make a bold decision that will make the lives of the bytelandians easier. They will minimize the maximum distance between any pair of persons by moving the main road to a horizontal line y = N, where N is an integer. If the main road is already at the optimal position, it will not be moved.
You will be given the 'x' and 'y' coordinates of the houses, print the maximum distance between any pair of persons after the main road is moved to the optimal position.
Input
The first line is T (3 ≤ T ≤ 1,000), the number of test cases, then T test cases follows.
Each test case starts with N (2 ≤ N ≤ 50), the number of persons in byteland.
then N lines, each one with two integers separated by a space.
Each one of these integers is the x and y coordinates, respectively, of a bytelandian home.
Constraints:
-The absolute value of each x and y coordinate will be between 0 and 109, inclusive.
Output
For each test case print out the required distance in a single line.
Example
Input:
3
3
1 4
4 1
1 1
5
-1 -1
-2 3
-1 -3
0 0
2 3
4
1 1
1 10
1 100
1 1000
Output:
6
9
999