Classical Minimization Problem
시간 제한2초메모리 제한1024 MB
서로 다른 2n개 점을 짝지어 x좌표나 y좌표가 같은 쌍의 수를 최소로 만들고, 그 짝들을 출력한다.
문제
You are given distinct points on a plane. Point has integer coordinates .
Points and are a friendly pair if either or .
Form pairs of points. Every point must belong to exactly one pair. The number of friendly pairs among your pairs must be minimized.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The -th of the next lines contains two integers and , denoting the coordinates of the -th point (). All points are distinct.
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, print a non-negative integer , denoting the minimum possible number of friendly pairs.
In the -th of the next lines, print two integers and , denoting a pair formed by points and (; ).
Every integer from to must appear among and exactly once. The number of indices such that points and are a friendly pair must be equal to .