Pahom on Water

No attempts yetTime limit1sMemory limit128 MB

Problem

Pahom on Water is an interactive game inspired by a short story of Leo Tolstoy about a poor man whose greed for land costs him everything. The starting screen shows a number of circular pads, each painted with a colour from the visible-light spectrum. A colour is identified by its frequency (in THz). Several pads may share the same colour, except for red and violet: there is exactly one red pad (the lowest frequency, 400 THz) and exactly one violet pad (the highest frequency, 789 THz).

Two pads may overlap, and one pad may even fully contain another pad of a different colour, but two pads never merely touch at their boundary. Pahom starts on the red pad.

The goal is to walk Pahom from the red pad to the violet pad and then back to the red pad, obeying these rules:

  1. While walking from the red pad toward the violet pad, Pahom may step from pad $\alpha$ to pad $\beta$ if they share a common overlapping region and the frequency of $\alpha$ is strictly less than the frequency of $\beta$.
  2. While walking back from the violet pad toward the red pad, Pahom may step from pad $\alpha$ to pad $\beta$ if they share a common overlapping region and the frequency of $\alpha$ is strictly greater than the frequency of $\beta$.
  3. Every coloured pad except the red pad disappears the moment Pahom steps off it.

For each game instance, decide whether at least one full round trip (red → violet → red) is possible.

Input

The first line contains an integer $K$ ($1 \le K \le 50$), the number of game instances. Each instance begins with a line containing an integer $N$ ($2 \le N \le 300$), the number of pads, followed by $N$ lines, one per pad. Each pad line contains the colour frequency, the $x$- and $y$-coordinates of the pad's centre, and the pad's radius, separated by single spaces.

The frequency is a real number with at most three decimal places. The coordinates and the radius are integers given in metres. Every integer value lies in the range $-10000$ to $10000$ inclusive. In every instance all frequencies lie between $400.0$ and $789.0$ inclusive, exactly one pad has frequency $400.0$, and exactly one pad has frequency $789.0$.

Output

For each instance, print a single line containing Game is VALID if a valid round trip exists, or Game is NOT VALID otherwise.