Under construction

Still being built. Things may change

Mines

Time limit1sMemory limit128 MB

Summary
Trigger the fewest mines so chain reactions through overlapping blast squares detonate all N mines.
Level

Medium7 of 10

Topics
Graph, DFS, Topological sort
Solved
No attempts yet

Problem

There are NN mines buried in an old battlefield. Each mine affects an axis-parallel square area determined by its performance. Treat the mine's location as the center of that square area. When a mine explodes, every mine whose center lies inside the exploding square area also explodes. By chain reaction, the mines inside the square areas of those newly exploded mines explode as well.

A mine lying exactly on the boundary of an exploding square area also explodes. In the figure below, if mine 4 is triggered first, mines 3 and 6 explode. If mine 1 is triggered first, mine 4 explodes, and the following blast makes mines 3 and 6 explode too. Therefore, triggering mines 1, 2, and 5 causes every mine to explode.

Given NN mines on a two-dimensional plane, each with its explosion performance described as a square area, write a program that finds the minimum number of mines you must trigger directly so that all mines explode.

Input

The input is read from standard input. It consists of TT test cases. The first line contains the number of test cases TT. Each test case begins with a line containing the number of mines NN (3≤N≤2 0003 \le N \le 2\,000). Each of the next NN lines contains three integers xx, yy, and dd, where xx and yy are the coordinates of the mine and dd is the side length of the square that represents its explosion performance (1≤x,y≤10 000 0001 \le x, y \le 10\,000\,000, 1≤d≤1 000 0001 \le d \le 1\,000\,000). Since the square is centered at (x,y)(x, y) with side length dd, the distance from the center to each side is d/2d/2.

Output

Write the result to standard output. For each test case, print exactly one line containing the minimum number of mines that must be triggered directly so that all mines explode.

Examples1

  1. Example 1

    Input
    2
    6
    6 11 10
    10 17 4
    12 10 4
    10 7 6
    5 4 6
    12 5 2
    4
    6 7 8
    9 10 4
    11 5 4
    15 9 8
    
    Expected output
    3
    2