Repeated Permutation Cipher

No attempts yetTime limit1sMemory limit128 MB

Problem

Bob and Alice began using a brand-new encryption scheme. It is not a public-key cryptosystem; instead it relies on a secret key known only to the two of them.

The secret key is a sequence of nn distinct integers a1,a2,,ana_1, a_2, \dots, a_n, each greater than 00 and at most nn. In other words, aa is a permutation of 11 through nn.

Encryption works as follows. Write the message under the key so that each character of the message lines up with a number of the key. The character at position ii in the message is moved to position aia_i in the encrypted message. The resulting text is then encrypted again in the same way, and this is repeated a total of kk times. After the kk-th encryption the result is exchanged.

The length of the message is always at most nn. If the message is shorter than nn, spaces are appended to its end so that its length becomes exactly nn.

Given the key and several pairs of a repeat count kk and a message, write a program that outputs each message after it has been encrypted kk times.

Input

The input consists of several blocks.

The first line of each block contains an integer nn (0<n2000 < n \le 200). The next line contains the key: nn integers, pairwise distinct and each between 11 and nn, separated by spaces. The following lines each contain an integer kk and a message of ASCII characters, separated by a single space. Each line ends with an end-of-line character, which is not part of the message. A block ends with a line containing only the number 00.

After the last block, a separate line containing only the number 00 marks the end of the input.

kk may be very large.

Output

For each (repeat count, message) pair, print the encrypted message on its own line. Every printed line has exactly nn characters, preserving any trailing spaces of the padded message. The results of the blocks are printed in the order they appear in the input, with no blank line between blocks.