Nice Shape
시간 제한4초메모리 제한512 MB
n개의 룩이 주어질 때, 어떤 네 개의 룩이 축에 평행한 직사각형의 네 꼭짓점을 이루도록 만드는 최소 이동 횟수를 구한다.
문제
You are given rooks on the different cells of the infinite chessboard.
The -th of them is in the cell .
In one move you can move any rook to any cell in the same row/column. In other words, in one move you can choose any and then either replace to any other integer or replace to any other integer. You can't move a rook to the cell with some other rook.
Four different rooks form a nice shape if you can find a rectangle such that are its corners. In other words, if the set of cells is equal to the set of cells for some integers with and .
For example, the white rooks in the following picture form a nice shape.

Your goal is to find the minimum number of moves that you can perform to get a nice shape.
In other words, you need to find the minimum number of moves that you can perform, such that after them it will be possible to find a rectangle with four rooks in its corners.
입력
The first line of input contains one integer (): the number of test cases.
The description of test cases follows.
The first line contains one integer ().
The -th of the next lines contains two integers ()
For each pair with , or .
The total sum of is at most .
출력
For each test case, print one integer: the minimum number of moves you need to perform to obtain at least one nice shape among given rooks.
힌트
One of the possible optimal solutions for the first test case of the example:

One of the possible optimal solutions for the second test case of the example:
