403380: GYM101147 F Bishops Alliance

Memory Limit:256 MB Time Limit:9 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Bishops Alliancetime limit per test9 secondsmemory limit per test256 megabytesinputbishops.inoutputstandard output

Chessforces is coming into a great war. The Knights Alliance is aiming to attack the Bishops Alliance land, it is up to you to help bishops defending their homeland.

In order to defeat the attacking knights, bishops want to make their defense line as big as possible. Defense line is a set of bishops on the chessboard where each pair of bishops in this set satisfies OK relation. OK relation between bishop i and bishop j is satisfied if they are on the same diagonal and the number of squares on the diagonal path between i and j is at least equal to pi2 + pj2 + C, where pk is privacy distance for bishop k and it is given for each bishop on the board, C is a given constant. Note that the path between two bishops includes both bishops squares.

Given the coordinates of each bishop on the chessboard, help them to find the defense line with maximum number of bishops.

Input

First line contains number of test cases T. Each test case contains one line with (0 < n ≤ 105) size of the chessboard edge, (0 < m ≤ 105) number of bishops and the constant (0 ≤ C ≤ 105) then m line follows, the ith line of them contains three integers: (1 ≤ ri, ci, pi ≤ n) where (ri,ci) is row number and column number of the ith bishop and pi is the privacy of the ith bishop.

Output

Print a single integer, the size of the defense line with maximum number of bishops.

ExampleInput
1
8 5 2
7 7 1
4 4 1
3 5 1
2 6 2
4 8 1
Output
2
Note

Large I/O files. Please consider using fast input/output methods.

First test case explanation, columns go from left to right and rows go up to bottom, bishops labeled with borders are included in the defense line.

加入题单

算法标签: