The Grille

Time limit1sMemory limit128 MB

Problem

In the 16th century there were no computers, yet messages still had to be protected from the wrong readers. Old tricks -- shaving a slave's head, writing the message on the scalp, waiting for the hair to grow back, and sending the slave through hostile territory -- could work, but they were painfully slow. Faster methods were needed. One of them is the grille cipher, first described by the Italian mathematician Girolamo Cardano.

Both enciphering and deciphering rely on a tool (the cipher key) called the grille, and both parties must own the same one. A grille is a square grid of $N \times N$ unit cells; some cells are solid and some are cut out to form holes.

Suppose a grille has $m$ holes. To encipher, write the first $m$ letters of the message into the holes, going row by row from top to bottom and, within each row, from left to right. Then rotate the grille 90 degrees clockwise and write the next $m$ letters into the holes in the same reading order. Rotate again and write another $m$ letters, then rotate once more and write the final $m$ letters. If any cells are still empty, fill them with random letters so the ciphertext looks more secure. Note that the grille is rotated, not the message.

To decipher, run the same procedure but read the letters through the holes instead of writing them.

Input

The input contains several test cases. Each test case describes one grille and one ciphertext.

Each test case begins with a line containing an integer $N$ ($1 \le N \le 1000$), the size of the grille. The next $N$ lines describe the grille; each line contains exactly $N$ characters, each either # (solid material) or O (the uppercase letter O, a hole).

In practice a grille's holes are arranged so that no ciphertext position is ever used more than once. Here that is not guaranteed: after the rotations several holes may fall on the same ciphertext position. The deciphering procedure is nevertheless identical.

After the grille come another $N$ lines holding the ciphertext; each line contains exactly $N$ uppercase letters.

A line containing a single 0 follows the last test case.

Output

For each test case, print the deciphered message on its own line, with no spaces.