The city center of an unnamed Nordic university town was once a medieval town of narrow, winding streets, completely surrounded by a high wall that protected it from Swedish invaders and other unwanted visitors. The wall has since been torn down and replaced by a ring of interconnecting roads that circles the entire old part of the town. The streets inside remain much as they were in the Middle Ages, which clashes with the modern demand for car access. The result is a maze of narrow one-way lanes that all look alike, mixed with slightly wider two-way streets.
Changing the traffic routes in such a town can easily cause unexpected side effects unless you plan carefully in advance. As the story goes, a prominent member of the city council once submitted a proposal for sweeping changes to how traffic in the city center should be organized. The proposal had the merit that it would be very easy to drive in to the central square, but unfortunately it would also be impossible to drive back out again. That council member later became minister of justice under the slogan that society should be harder on criminals — "it should be easy to go to jail, but difficult to get out again."
To avoid mistakes like this one, the city planners need you to build a tool that can spot traffic problems while the plan is still on the drawing board. The planners must be warned about two situations. The first is that some street in the city center exists from which you cannot reach the surrounding ring of roads — that is, you are trapped inside the city. The second is that some street exists that cannot be reached from the surrounding ring of roads — that is, it is unreachable.
The input describes how the streets connect to one another and to the surrounding ring of roads. Connections are directed: being able to drive from one street to another does not mean you can drive back. Each street (or a segment of a street) inside the city center is represented by an arbitrary integer id greater than $0$, with $0 < \text{id} < 1000$. The surrounding ring of roads is represented by the special id $0$.
The first line contains a single integer $n$, the number of streets (including the surrounding ring), with $0 < n \le 1000$.
Each of the next $n$ lines describes one street (in no particular order, and the surrounding ring is included). The first integer on the line is the street's id, the second integer is the number of other streets that can be reached directly from this street, and the remaining integers are the ids of those reachable streets.
For each street on which you would be trapped inside the city, print one line TRAPPED X, where X is replaced by the id of that street.
Then, for each street inside the city that is unreachable from the surrounding ring of roads, print one line UNREACHABLE X, where X is replaced by the id of that street.
If there are no problems — you are not trapped on any street and every street is reachable — print a single line containing NO PROBLEMS.
If several streets cause you to be trapped, or are unreachable, list them in the same order in which they appeared in the input (within each category).