Choose Your Own Adventure

Time limit1sMemory limit128 MB

Problem

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.

Input

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:

  • A line with an integer $X$ ($1 < X < 100$), the number of pages.
  • Then $X$ lines, one per page: the $i$-th of these lines describes page $i$. Page 1 is always a choice page. On each line the fields are separated by single spaces:
    • Line type — a single character: C for a choice page or E for an end page.
    • Text — a string enclosed in double quotes. Including the quotes it is at most 256 characters. The quotes are delimiters only and are not part of the text; the text contains no double quotes.
    • Choices — only on a choice page (C): two integers from 1 to $X$, the pages the reader may turn to next.
    • Ending type — only on an end page (E): the word HAPPY or GRISLY. Each story has exactly one happy ending.

Output

For each story, in order:

  1. Print a line STORY k, where $k$ is 1 for the first story, 2 for the second, and so on.
  2. Then print the text of the pages along the path that starts on page 1 and ends at the happy ending, one page of text per line. For each story this path is unique.