Under construction

Still being built. Things may change

Certain Scientific Railgun

Time limit1sMemory limit512 MB

Summary
Find the least axis-parallel travel from (0, 0) so that every robot shares a row or column with some visited point.
Level

Medium7 of 10

Topics
Graph, Union-find, Greedy
Solved
No attempts yet

Problem

Misaka Mikoto is the third-ranked Level 5 esper in Academy City and is nicknamed Railgun after her signature move. One day, several evil robots invade Academy City, and Misaka plans to terminate all of them.

Consider Academy City as a 2-dimensional plane. There are nn robots in total, and the position of the ii-th robot is (xi,yi)(x_i, y_i). Misaka starts moving from (0,0)(0, 0). Her railgun ability terminates all robots that share the same xx- or yy-coordinate with her. If Misaka is located at (xm,ym)(x_m, y_m), every robot with xi=xmx_i = x_m or yi=ymy_i = y_m is terminated.

Misaka hates decimals and Euclidean geometry. She moves only from one integer point to another integer point, and each move can only be horizontal (parallel to the xx-axis) or vertical (parallel to the yy-axis). Moving around the city is tiring, so calculate the minimum distance she must move to terminate all robots.

Input

There are multiple test cases. The first line contains an integer TT, the number of test cases. Each test case is given as follows.

The first line contains an integer nn (1≤n≤1051 \leq n \leq 10^5), the number of robots.

The following nn lines each contain two integers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9), the position of the ii-th robot.

The sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, output one line containing one integer, the minimum distance Misaka needs to move to terminate all robots.

Hint

In the second sample test case, Misaka should first go to (0,1)(0, 1), then to (0,2)(0, 2), then to (0,−3)(0, -3), then to (0,−4)(0, -4).

In the third sample test case, Misaka should first go to (1,0)(1, 0), then to (1,1)(1, 1), then to (3,1)(3, 1).

Examples1

  1. Example 1

    Input
    3
    2
    0 1
    1 0
    4
    1 1
    -3 -3
    4 -4
    -2 2
    4
    1 100
    3 100
    -100 1
    3 -100
    
    Expected output
    0
    8
    4