Brazil#6469

Brazil

1 second
128 megabytes
Very easy

In Terry Gilliam's film "Brazil", we are introduced to a grim world ruled by an overgrown and inefficient bureaucratic system.

Although one can trace certain parallels with Orwell's dystopia "1984", the world of "Brazil" lacks the same terrifying efficiency. The bureaucracy is entirely dysfunctional, and society depends on outdated, barely functioning machines.

Overall, "Brazil" is definitely a film worth watching. Many of its scenes vividly depict the absurdity and meaninglessness of bureaucratic machinery.

Here are the main principles of the system:

You are to simulate this system. The simulation consists of a sequence of queries of two types: either "bureaucrat receives a new form ", or "bureaucrat B_1 transfers all their forms to bureaucrat B_2". Initially, no bureaucrat has any forms.

Input

Consists of at most 10^5 + 1 lines. Each line has one of the following formats:

  • — bureaucrat with ID receives a new form with ID and places it on top of their stack.

  • M~b_1~b_2 — bureaucrat with ID b_1 transfers their entire stack of forms to bureaucrat with ID b_2 (if b_1 has no forms, nothing happens).

  • — end of simulation. This line occurs exactly once and is always the last in the input.

Output

Print the final state of all bureaucrats who have non-empty stacks by the end of the simulation. For each such bureaucrat, print a line of the form:

id: f_1~f_2~\ldots~f_n

where is the bureaucrat's ID, and f_1, f_2, \ldots, f_n are the IDs of the forms on their desk, listed from top to bottom. The bureaucrats should be listed in increasing order of their IDs. Spaces must appear exactly where shown in the output format.

Examples

Let us examine the sequence of queries in the following example:

  1. Bureaucrat receives a new form .

  2. Bureaucrat transfers their form ( form) to bureaucrat .

  3. Bureaucrat transfers their form ( form) back to bureaucrat .

  4. Bureaucrat attempts to transfer forms ( forms) to bureaucrat .

  5. Bureaucrat receives a new form .

  6. Bureaucrat receives a new form .

  7. Bureaucrat transfers all their forms ( forms) to bureaucrat .

Example 1

Loading
Loading

Example 2

Loading
Loading