#K48582. Taco Treasure Hunt

    ID: 28452 Type: Default 1000ms 256MiB

Taco Treasure Hunt

Taco Treasure Hunt

You are given a set of adventurers and a set of treasures. Each adventurer is located at a coordinate on a 2D plane, and so is each treasure. The distance between two points \( (x_1,y_1) \) and \( (x_2,y_2) \) is defined as the Manhattan distance:

\( d((x_1,y_1),(x_2,y_2)) = |x_1-x_2| + |y_1-y_2| \)

Your task is to assign each adventurer to a unique treasure such that the total distance traveled by all adventurers is minimized. You are guaranteed that the number of adventurers is equal to the number of treasures in each test case.

The input contains multiple test cases. For each test case, compute and output the minimum total Manhattan distance for a valid assignment.

inputFormat

The first line of input contains an integer \( T \) representing the number of test cases.

For each test case, the first line contains an integer \( n \) representing the number of adventurers (and treasures). The following \( n \) lines each contain two integers denoting the coordinates of the adventurers.

The next \( n \) lines each contain two integers denoting the coordinates of the treasures.

All input values are separated by whitespace.

outputFormat

For each test case, output a single integer on a new line representing the minimum total Manhattan distance required for the adventurers to collect the treasures.

## sample
3
2
1 1
2 2
1 2
2 1
3
1 2
2 1
3 3
1 1
2 2
3 1
3
1 2
3 4
5 6
2 2
4 4
6 6
2

4 3

</p>