Linden Mayor System

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Aristid is the mayor of a town called Linden. He and the townsfolk love fractals. One day, Aristid decides to genetically alter trees so that they have mathematically pleasing structures. It turns out that the people of Linden will support this idea only if the trees are sufficiently "tree-like." So Aristid came up with the following system to generate realistic looking trees. Since he's a little vain, he decided to call it the Linden Mayor System.

Start with a sequence of letters S_0S\_0. This is the seed that will be used to generate the rest of the tree. Next define some rules to model the branching behavior of the tree. A rule will have the form xyx \rightarrow y, indicating that the letter xx will be replaced with the sequence yy. By applying these rules to S_0S\_0, the new sequence S_1S\_1 is created. These rules can be applied over and over to produce new sequences.  In general, to create S_n+1S\_{n+1} from S_nS\_n, replace all the letters in sequence S_nS\_n according to the rules. Some letters may not have a rule associated with them.  Such terminal letters are not replaced.

As an example, consider the starting sequence A with rules: A \rightarrow AB and B \rightarrow A. The first four iterations are as follows:

S_0S\_0:AStarting sequence.
S_1S\_1:ABA is replaced with AB by rule A \rightarrow AB. Note that rule B \rightarrow A couldn't be applied.
S_2S\_2:ABAAgain, A is replaced by AB but B is replaced with A (rule B \rightarrow A).
S_3S\_3:ABAABKeep applying rule A \rightarrow AB for A's and rule B \rightarrow A for B's...
S_4S\_4:ABAABABAThis is the resulting sequence after four iterations.

입력

The first line will contain two positive integers: 0n260 \leq n \leq 26 and 0m50 \leq m \leq 5.  Following this will be nn lines defining the rules for a Linden Mayor System. Each line is of the form: xx -> yy, indicating that xx is replaced by yy. xx and yy will contain only uppercase letters from A to Z, and the length of yy is guaranteed to be at most five.  The last line will contain the starting sequence S_0S\_0 which will be no longer than 3030 characters and will contain only uppercase letters from A to Z.

출력

Output the resulting sequence S_mS\_m which is produced after mm iterations.