You are aboard the luxury liner Neptune, which is flooding fast. Find out whether you can escape the ship and reach the rescue team before you drown.
The ship's layout is described by a set of locations (cabins, lounges, and other rooms) and directed paths (hallways, elevators, Christmas trees, and stairs) between them, each with a travel time. You must find the shortest time it takes to get from your starting location to the rescue team.
A series of explosions floods the ship. Each location floods at a fixed time, and when a location floods, every path leading into or out of it floods as well. If you are inside a location, or on a path, at the very moment it floods, you drown. You may not travel through a location once it has flooded.
You win ties: if you reach a location that is not yet flooded at the exact moment the path you were traveling on floods, you survive; and if you reach the rescue team's location at the exact moment that location floods, you also survive.
The first line contains a single integer $N$ ($1 \le N \le 100$), the number of data sets. Each data set is given as follows.
Paths are directed: the time from location $i$ to location $X$ need not equal the time from location $X$ to location $i$, and some paths exist in only one direction.
For each data set, print a single line with the shortest time in minutes it takes to reach the rescue team from your starting location without drowning. If it is impossible to reach the rescue team, print GENE HACKMAN instead.