Watering the Flower Garden

No attempts yetTime limit1sMemory limit256 MB

Problem

The garden is a square grid with 10610^6 rows and 10610^6 columns. It holds NN flowers, and flower ii sits in row rir_i, column cic_i.

You place sprinklers in the garden. A sprinkler goes on any empty cell, meaning a cell with no flower, and from that cell it shoots four streams of water along the grid: up, right, down, and left.

Flowers have a special property. A flower that receives water from any direction shoots water from its own cell in the same four directions: up, right, down, and left. Vertical streams and horizontal streams run at different heights, so they pass through each other instead of colliding. A stream runs to the edge of the grid, and neither a flower nor another stream blocks it.

Find the smallest number of sprinklers that waters all NN flowers.

Input

The first line holds the number of test cases TT (1T201 \le T \le 20). Each test case has this form.

  1. The first line holds the number of flowers NN (1N1000001 \le N \le 100000).
  2. The next NN lines hold the row and the column of one flower, rir_i and cic_i (1ri,ci10000001 \le r_i, c_i \le 1000000). No two flowers share a cell.

Output

For each test case, print on its own line the smallest number of sprinklers that waters every flower.

Hint

The two pictures below show placements that use the smallest number of sprinklers.

Placement for the first example test case

The first example test case

Placement for the second example test case

The second example test case