The Princess and the Magic Mirror

Print an N by N picture unchanged, mirrored left to right, or flipped top to bottom according to the given mood number.

Easy1MatrixImplementationInterviewNo attempts yetTime limit2sMemory limit256 MB

Problem

Princess Jiyoung of Minho Fortress, in the kingdom of Cheon, is afraid that her beauty will fade with time, so she checks herself in the mirror dozens or hundreds of times a day.

One day the magic mirror grew tired of showing the same picture every day and decided to reflect the princess flipped left to right or top to bottom, depending on its mood that day.

The mood of the magic mirror is a natural number from 1 to 3, and a larger number means an angrier mirror. With mood 1 the mirror shows the princess exactly as she is, with mood 2 it shows her flipped left to right, and with mood 3 it shows her flipped top to bottom.

Given the size of the square magic mirror, the original picture of the princess, and the mood of the mirror, print the picture the magic mirror shows.

Input

The first line contains a natural number NN (2N1002 \le N \le 100), the size of the square magic mirror.

Each of the next NN lines contains NN characters, the original picture of the princess. The magic mirror draws its picture with uppercase and lowercase letters only.

The last line contains an integer KK (1K31 \le K \le 3), the mood of the magic mirror.

Output

Print the picture the magic mirror shows as an N×NN \times N square, according to its mood. Flipping means reversing the positions of the characters given in the input.

If KK is 1, print the input unchanged. If KK is 2, reverse the order of the characters in every line. If KK is 3, reverse the order of the lines.