Beverages (Tasting Order)#11451

Beverages (Tasting Order)

1 second
128 megabytes
Medium

A robot is tasked with taste-testing a collection of different beverages for a research laboratory. Every beverage can be served at a certain temperature, and the robot is programmed to always start from colder drinks and gradually proceed to hotter ones. Once it finishes a hotter drink, it never goes back to a colder one—hence, the temperature of the drinks never decreases during tasting.

Your job is to help determine a valid order for tasting the drinks according to these rules and the relations provided.

Input

Each test case starts with (1 \le n \le 100), the number of available beverages. Then, lines follow, each containing the name of one beverage. A name has fewer than characters and contains no whitespace.

Then there is another line with an integer (0 \le m \le 200), followed by lines in the form b_1\ b_2, indicating that beverage b_2 must be tasted after beverage b_1 (i.e., b_2 is served hotter than b_1). This relation is transitive: if b_1\ b_2 and b_2\ b_3 both exist, then b_1 must come before b_3. There is a blank line after each test case.

If there is no relation between two beverages, the robot should taste the one that appears first in the input first. The input is terminated by the end of file (EOF).

Output

For each test case, print:

"Case #C: The robot should taste beverages in this order: b_1\ b_2\ ...\ b_n."

where is the number of the test case, starting from , and b_1\ b_2\ ...\ b_n is a list of beverages such that no drink is tasted before a colder one. After each test case, print a blank line.

Examples

Example 1

Loading
Loading