Professor John

Time Limit: 1 Second    Memory Limit: 32768 KB

Sunny Cup 2003 - Preliminary Round

April 20th, 12:00 - 17:00

Problem H: Professor John


Professor John is investigating a math problem. He has obtained some relations among several variables. Now he would like to know if there are any other relations that can be deduced from these obtained ones. Since he has been working for too long, Professor John decides to grant himself a vacation while assigning you to do the job. Are you ready?

Input

The first line of input contains an integer N, which is the number of test cases. Then N test cases follow.

For each test case:

the 1st line contains a positive integer m (<= 100) which is the number of given relations;

the following m lines each contains a given relation, in the format

Variable1

or

Variable1>Variable2

A "Variable" is represented by a capital character. There will not be conflicting relations given.

Output

For each test case, first print in one line "Case d:" where d is the number of the test case, start counting from 1.

Then output all the relations which can be deduced from the given relations in alphabetical order, in the format Variable1
If no new relation is found, output "NONE" in one line.

Sample Input

2
3
A
C>B
C
2
A
C

Sample Output

Case 1:
A
A
B
Case 2:
NONE
Submit

Source: Zhejiang University Local Contest 2003, Preliminary