407255: GYM102726 G Character Quilt

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Character Quilttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Terrence, like the rest of us, occasionally finds himself stuck in a Zoom call that is not particularly exciting, perhaps even boring. At times like these, he likes to send Direct Messages to his friends on the call to liven up the mood. Rather than sending something normal like links to memes, Terrence prefers to send what he calls a Character Quilt.

A Character Quilt is a rectangular grid of transformed Character Tiles, and a Character Tile is simply a square grid of characters. In order to construct a Character Quilt, Terrence starts by defining $$$N$$$ aesthetically pleasing Character Tiles, where each Character Tile consists of a grid of characters with dimensions $$$S \times S$$$. After that, Terrence defines the overall Character Quilt which is a $$$W\times H$$$ grid of Character Tiles. For each tile slot in the quilt, he specifies the index $$$i$$$ ($$$0\leq i <N$$$) of the tile that should fill that slot.

To make things more interesting, Terrence also specifies a transformation indicator $$$t$$$ for each tile slot in the quilt, indicating what kind of transformation should be applied to the source Character Tile. When $$$t=0$$$, no transformation is applied. When $$$t=1$$$, the Character Tile should be rotated 90 degrees clockwise. When $$$t=2$$$, the Character Tile is rotated 180 degrees. When $$$t=3$$$, the Character Tile should be rotated 270 degrees clockwise. When $$$t=4$$$, the Character Tile is flipped across the vertical axis (side-to-side), and lastly, when $$$t=5$$$, the Character Tile is flipped across the horizontal axis.

For example, with a $$$2\times 2$$$ tile $$$\matrix{ ab \cr cd \cr }$$$, below are the transformation results for each value of $$$t$$$.

$$$\begin{array}{|c|c|c|c|c|c|c|} \hline t: & 0 & 1 & 2 & 3 & 4 & 5 \cr \hline Tile: & ab & ca & dc & bd & ba & cd \cr & cd & db & ba & ac & dc & ab \cr \hline \end{array}$$$

Help Terrence automatically generate his Character Quilts so that he can rapidly spam his friends!

Input

The first line of input contains two integers: $$$N$$$ and $$$S$$$ ($$$1 \leq N, S \leq 15$$$). Then $$$N$$$ Character Tiles follow, each consisting of $$$S$$$ lines with $$$S$$$ characters.

The next line of input contains two integers: $$$W$$$ and $$$H$$$ ($$$1\leq W,H \leq 100$$$). $$$H$$$ lines follow. Each of these lines contain $$$W$$$ tile specifications where a tile specification is of the form $$$i:t$$$. The first number $$$i$$$ is the index of a Character Tile from the inputted list ($$$0$$$ represents the first tile and $$$N-1$$$ represents the last), and $$$t$$$ specifies the type of transformation to apply to that tile in the final quilt.

Output

Print the final Character Quilt, with all of the transformed Character Tiles filled into the right places.

ExampleInput
2 3
<<>
^<^
<>>
>*=
*+*
+=>
5 3
0:0 1:0 0:0 1:4 0:0
1:0 1:1 1:2 1:3 1:0
0:5 1:0 0:5 1:4 0:5
Output
<<>>*=<<>=*><<>
^<^*+*^<^*+*^<^
<>>+=><>>>=+<>>
>*=+*>>=+=*>>*=
*+*=+**+**+=*+*
+=>>*==*>>*++=>
<>>>*=<>>=*><>>
^<^*+*^<^*+*^<^
<<>+=><<>>=+<<>

加入题单

算法标签: