You know that many necrologues even the most heartfelt are very similar. Our partners from the ACM Company (Advanced Cemetery Management), which is a sponsor of today's thematic problem set, decided to disclose some secrets of skill. As soon as we got into the workshop of the word-painters we found out that:
- there are N (1 ≤ N ≤ 9) sample necrologues;
- each sample necrologue has not more than 1000 symbols (capital and small Latin letters, digits, punctuation marks, spaces and carriage return marks);
- each sample may contain not more than 10 references to other samples (the reference is marked by *, which is followed by a number of a sample that is referred to; the *-mark is used in the samples in no other way but as a reference mark).
A reference may be activated at a client's pleasure: the sequence *M is substituted with the sample necrologue number M (with all its references).
This system worked properly up to the moment that a very rich client entered the workshop. He wanted to add a stone to his mother's-in-law cairn and wished a necrologue according to the sample number 1 with all the references activated (including the ones that can appear after activating the references in the first sample, and so on).
It's necessary to write a program in order to understand if it's possible to fulfill the wishes of the client and what will appear in this necrologue.
The first input line contains a number N, an amount of the necrologues samples. Than follow the samples texts. Each samples starts from a new line and ends with the # symbol.
Consider the necrologue forming procedure that starts from the first sample, activates all the references than activates all the references in the result of the previous step and so on ad infinitum. If such a procedure leads to the text not longer than 106 symbols (spaces and line feeds are considered as symbols) you should output the necrologue text. You should output # otherwise.
She w*7s *7 *2 wom*7n.
Everyone loved her *5.
We will miss her *5.#
Some text *6#
Another text *4#
She was a wonderful woman.
Everyone loved her very much.
We will miss her very much.
Problem Author: Leonid Volkov
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003