Zombie Smash (Large)

Plan a route from the origin that smashes the most time-windowed zombies given Chebyshev travel time and a 750 ms weapon recharge.

Medium6Dynamic programmingSortingGraphNo attempts yetTime limit5sMemory limit512 MB

Problem

You are playing Zombie Smash. Zombies pop out of graves in a graveyard, and you smash them with your Zombie Smasher. The graveyard is a flat 2D grid. Each zombie pops out of a grave at some cell (X,Y)(X, Y), stands there for 1000 milliseconds, then drops back into the grave. At most one zombie stands at a grave at any moment.

You move to any one of the 8 cells adjacent to your cell in 100 ms, so you can go north, east, south, west, northwest, northeast, southwest and southeast. You may walk through a cell or stand on it even while a zombie occupies it. Reaching the cell of a standing zombie smashes that zombie instantly, but after a smash the Zombie Smasher takes 750 ms to recharge before it can smash again. You may keep moving while it recharges. For example, right after smashing a zombie at (0,0)(0, 0):

  • reaching and smashing a zombie at (1,1)(1, 1) takes 750 ms, or
  • reaching and smashing a zombie at (20,20)(20, 20) takes 2000 ms.

You start on cell (0,0)(0, 0) at time 0. After you play a level, you want to know how many zombies you could have smashed with optimal play.

Input

The first line contains one integer TT, the number of test cases. Each test case starts with a line holding one integer ZZ, the number of zombies in the level.

The next ZZ lines each contain 3 space separated integers XiX_i, YiY_i and MiM_i, describing where and when zombie ii appears.

  • XiX_i is the x coordinate of the cell where zombie ii appears.
  • YiY_i is the y coordinate of the cell where zombie ii appears.
  • MiM_i is the time at which zombie ii appears, in milliseconds after the start of the game. The interval in which the zombie can be smashed includes both endpoints: if you reach the cell at any time in [Mi,Mi+1000][M_i, M_i + 1000] with a charged Zombie Smasher, you smash the zombie in that cell.

Limits

  • 1T1001 \le T \le 100
  • 1Z1001 \le Z \le 100
  • 1000Xi,Yi1000-1000 \le X_i, Y_i \le 1000
  • 0Mi1000000000 \le M_i \le 100000000
  • Two zombies are never in the same place at the same time. If one zombie appears at (x,y)(x, y) at time tt, then every other zombie that appears at (x,y)(x, y) appears at or before t1001t - 1001, or at or after t+1001t + 1001.

Output

For each test case, print one line containing "Case #c: d", where c is the case number starting from 1, and d is the largest number of zombies you could have smashed in that level.