Under construction

Still being built. Things may change

Definite Values

Interview

Time limit1sMemory limit128 MB

Summary
Process a sequence of single-letter assignments, starting with only 'a' defined, and after each program part print the defined variables in alphabetical order.
Level

Easy3 of 10

Topics
Simulation, Hash map, Implementation
Solved
No attempts yet

Problem

A common mistake in programming is to use variables that have not been initialized. For example, in C and C++ every variable holds an indefinite value right after it is declared — it can be anything. Thus the following program

main()
{
    int x;
    printf("%d\n", x);
}

could print any number. But even in languages such as Pascal, where every value is initialized to zero, it is good practice to give variables definite values before using them, so as to avoid side effects when your code fragment is placed in a different context.

In general, deciding for a given program whether every variable has been assigned a value before it is read is undecidable. But if, as in this problem, you consider only a sequence of assignments, the problem becomes solvable.

Input

The input contains several program parts. Each part starts with an integer nn on a line by itself — the number of lines in that part. The following nn lines each contain an assignment of the form "variable1 = variable2", where each variable is a single lower-case letter.

The input is terminated by a part with n=0n = 0.

Output

Assume that before a program part is executed, variable a has a definite value while every other variable is undefined. An assignment "variable1 = variable2" makes variable1 definite only if variable2 currently has a definite value; otherwise variable1 becomes undefined. After executing each program part, print the names of the variables that have a definite value.

For each program part, first print the line "Program #k", where k is the program number starting from 1. On the next line print the names of the variables that have a definite value, sorted alphabetically, with one blank after each name. If no variable has a definite value, print "none".

Separate the outputs of consecutive program parts with a single blank line.

Examples6

  1. Example 1

    Input
    4
    b = a
    c = d
    d = b
    e = f
    1
    a = b
    0
    
    Expected output
    Program #1
    a b d 
    
    Program #2
    none
    
  2. Example 2

    Input
    1
    b = a
    0
    
    Expected output
    Program #1
    a b 
    
  3. Example 3

    Input
    3
    b = a
    c = b
    d = c
    0
    
    Expected output
    Program #1
    a b c d 
    
  4. Example 4

    Input
    2
    a = z
    b = a
    0
    
    Expected output
    Program #1
    none
    
  5. Example 5

    Input
    3
    b = a
    a = z
    a = b
    0
    
    Expected output
    Program #1
    a b 
    
  6. Example 6

    Input
    2
    b = a
    c = a
    1
    a = b
    2
    x = a
    y = x
    0
    
    Expected output
    Program #1
    a b c 
    
    Program #2
    none
    
    Program #3
    a x y