P15605 [CodeChef] KMHAMHA
提高
题目描述

Read problems statements in Mandarin Chinese here

City of Byteland can be described as a $2D$ grid of cells. Each cell may or may not contain a demon. You are given the list of cells that contain demons.

In a single Kamehameha attack, Goku can kill all the demons standing in a row or in a column. But using Kamehameha drains Goku's power. You are to tell the minimum number of Kamehameha attacks that will be required by Goku to destroy all the demons.

------ Input ------
The first line contains a single integer $T$, the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $N$, the number of cells where enemies are present. The description of the enemies follows.
The next $N$ lines contain two space separated integers $X$ and $Y$, the row and column of the cell in which a demon is present.

------ Output ------
For each test case, on a new line, print the minimum number of attacks that are required to kill all of the demons.

------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 1000$
$1 ≤ X, Y ≤ 10^{9}$

----- Sample Input 1 ------
1
3
0 0
1 0
0 1
----- Sample Output 1 ------
2

输入格式

见题面

输出格式

见题面

样例输入
1 3 0 0 1 0 0 1
样例输出
2