P21486 [HackerEarth] Alex is the most famous ringmaster(circus) of the Great Indian Circus from the movie Dhoom3 who has just come to your city to demonstrate his skills and leave you awestruck by his stage
普及
题目描述

Alex is the most famous ringmaster(circus) of the Great Indian Circus from the movie Dhoom3 who has just come to your city to demonstrate his skills and leave you awestruck by his stage performances. This time he is up with a new show which he named as 'Jungle me Mangal'.

This show is held in an artificially made jungle(forest) in your city. The artificial jungle looks like a cartesian plane when seen from a helicopter(top view) and has an artificial tree planted at some of the integer coordinates of the cartesian plane looking jungle.

This special show requires a monkey to start from any tree in the jungle and visit all the trees atleast once by jumping from one tree to another, but with a constraint that any monkey can only jump from one tree to another parallel to the axis of the cartesian plane(jungle).

Initially there are some trees planted in the jungle, that may or may not be sufficient for the monkey to visit all the trees.
You are asked to tell the minimum number of trees required to be planted so that the monkey could visit all the trees.

Input:

The first line contains a positive integer t denoting the number of test cases.
Each test case begins with a line containing a positive integer N, denoting the number of trees already planted in the jungle. N lines follow in each test case.

Each of the next N lines contains 2 positive integers x and y, the coordinates of the i'th tree.

Output:

Print the minimal number of trees required to be planted so that the monkey could visit all the trees starting from any tree by jumping from one tree to another.

Constraints:

1 ≤ t ≤ 10

1 ≤ N ≤ 1000

1 ≤ x, y ≤ 1000

SAMPLE INPUT
1
2
1 2
2 1

SAMPLE OUTPUT
1

输入格式

见题面

输出格式

见题面

样例输入
10 2 2 1 1 2 2 2 1 4 1 24 171 35 261 20 4 206 501 446 961 912 581 748 946 978 463 514 841 889 341 466 842 967 54 102 235 261 925 889 682 672 623 636 268 94 635 710 474 510 697 794 586 663 182 184 806 663 468 459 17 660 646 440 442 689 618 441 415 922 865 950 972 312 366 203 229 873 860 219 199 344 308 169 176 961 992 153 84 201 230 987 938 834 815 11 798 845 722 911 374 270 629 537 748 856 831 885 486 641 751 829 609 492 98 27 654 663 1 321 88 9 811 859 656 676 76 141 945 951 497 455 18 55 335 294 267 275 656 689 7 948 946 130 130 761 758 941 938 971 971 387 385 509 510 6 535 699 217 337 508 780 180 292 393 112 732 888 14 25 23 499 406 193 266 823 751 219 227 101 138 978 992 43 74 997 932 237 189 634 538 774 740 842 767 742 802
样例输出
280 220 304 294 32 192 171 282 295 300