Classical Minimization Problem

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

문제

You are given 2n2n distinct points on a plane. Point ii has integer coordinates (x_i,y_i)(x\_i, y\_i).

Points ii and jj are a friendly pair if either x_i=x_jx\_i = x\_j or y_i=y_jy\_i = y\_j.

Form nn pairs of points. Every point must belong to exactly one pair. The number of friendly pairs among your nn pairs must be minimized.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1051 \le n \le 10^5).

The ii-th of the next 2n2n lines contains two integers x_ix\_i and y_iy\_i, denoting the coordinates of the ii-th point (109x_i,y_i109-10^9 \le x\_i, y\_i \le 10^9). All points are distinct.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

출력

For each test case, print a non-negative integer kk, denoting the minimum possible number of friendly pairs.

In the ii-th of the next nn lines, print two integers a_ia\_i and b_ib\_i, denoting a pair formed by points a_ia\_i and b_ib\_i (1a_i,b_i2n1 \le a\_i, b\_i \le 2n; a_ib_ia\_i \ne b\_i).

Every integer from 11 to 2n2n must appear among a_ia\_i and b_ib\_i exactly once. The number of indices ii such that points a_ia\_i and b_ib\_i are a friendly pair must be equal to kk.