Rout 66

Time limit1sMemory limit128 MB

Problem

While the Romans may have had a fancy number system, the Visigoths — led by Alareiks, known today as Alaric I — took Rome on August 24, 410. It was the first time in eight hundred years that Rome had fallen to a foreign army.

You will simulate a considerably less bloody (and less realistic) rout of defenders by a potentially overwhelming invading force.

Consider a group of invaders of strength $I$ advancing on a stronghold whose defenders have strength $J$ and whose fortifications have strength $S$, at a distance $D$ ahead. The invaders' Routing Force $F$ is their strength times the distance:

$$F = I \cdot D$$

and the defenders' Blocking Force $B$ is the defender strength times the square of the fortification strength:

$$B = J \cdot S^2$$

If $F \le B$, the rout fails and the invaders are driven off. If $F > B$, the rout succeeds: every defender is driven off and the invaders advance. Their strength is then reduced by the fraction $B / F$ — the ratio of the defenders' Blocking Force to the invaders' Routing Force — and rounded up so that a successful rout always leaves at least one soldier:

$$I_{\text{new}} = \left\lceil I \left(1 - \frac{B}{F}\right) \right\rceil$$

Once the invaders break through a stronghold, that stronghold's location becomes the new starting point for measuring the distance to the next stronghold, and so on, until the invaders either break through every stronghold or are completely routed.

All strongholds lie on a straight line from the invaders' starting position and must be engaged in order from nearest to furthest. No two strongholds occupy the same location within a data set.

Input

The first line contains an integer $N$ ($1 \le N \le 100$), the number of data sets. Each data set consists of:

  • a line with an integer $E$ ($1 \le E \le 20$), the number of strongholds;
  • $E$ lines, each containing three space-separated integers $D$, $J$, $S$ ($1 \le D, J \le 10000$; $1 \le S \le 50$). $D$ is the distance of the stronghold from the invaders' starting position (the strongholds may be listed in any order and must be processed from nearest to furthest), while $J$ and $S$ are the defender strength and the fortification strength;
  • a line with an integer $I$ ($1 \le I \le 30000$), the strength of the invading force.

Output

For each data set, print ROUT! if the invaders break through every stronghold, or RETREAT! if they cannot.