After reading a choose-your-own-adventure book far too many times, James is fed up with it. No matter which choices he makes, the hero Kenny always meets a grim end — he falls down an abandoned mine shaft, gets run over by a busload of nuns, or is devoured by stray cats. Flipping through the book, James spotted the page with the happy ending, but he cannot work out how to reach it by following the rules. Luckily, he can write a program to do it for him.
Given a story laid out as numbered pages, find the sequence of pages that starts on page 1 and leads to the happy ending, and print the text on each of those pages.
The first line contains an integer $n$ ($1 \le n \le 100$), the number of stories. The stories follow with no blank lines between them.
Each story is described as follows:
C for a choice page or E for an end page.C): two integers from 1 to $X$, the pages the reader may turn to next.E): the word HAPPY or GRISLY. Each story has exactly one happy ending.For each story, in order:
STORY k, where $k$ is 1 for the first story, 2 for the second, and so on.