Nice Shape

아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

You are given nn rooks on the different cells of the infinite chessboard.

The ii-th of them is in the cell (r_i,c_i)(r\_i, c\_i).

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 ii and then either replace r_ir\_i to any other integer or replace c_ic\_i to any other integer. You can't move a rook to the cell with some other rook.

Four different rooks a,b,c,da, b, c, d form a nice shape if you can find a rectangle such that a,b,c,da,b,c,d are its corners. In other words, if the set of cells (r_a,c_a),(r_b,c_b),(r_c,c_c),(r_d,c_d)\\{(r\_a, c\_a), (r\_b, c\_b), (r\_c, c\_c), (r\_d, c\_d)\\} is equal to the set of cells (x_1,y_1),(x_1,y_2),(x_2,y_1),(x_2,y_2)\\{(x\_1, y\_1), (x\_1, y\_2), (x\_2, y\_1), (x\_2, y\_2)\\} for some integers x_1,x_2,y_1,y_2x\_1, x\_2, y\_1, y\_2 with x_1x_2x\_1 \neq x\_2 and y_1y_2y\_1 \neq y\_2.

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 tt (1t25,0001 \leq t \leq 25\\,000): the number of test cases.

The description of tt test cases follows.

The first line contains one integer nn (4n100,0004 \leq n \leq 100\\,000).

The ii-th of the next nn lines contains two integers r_i,c_ir\_i, c\_i (1r_i,c_i1091 \leq r\_i, c\_i \leq 10^9)

For each pair i,ji, j with iji \neq j, r_ir_jr\_i \neq r\_j or c_ic_jc\_i \neq c\_j.

The total sum of nn is at most 100,000100\\,000.

출력

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: