407255: GYM102726 G Character Quilt
Description
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!
InputThe 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.
OutputPrint the final Character Quilt, with all of the transformed Character Tiles filled into the right places.
ExampleInput2 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:5Output
<<>>*=<<>=*><<> ^<^*+*^<^*+*^<^ <>>+=><>>>=+<>> >*=+*>>=+=*>>*= *+*=+**+**+=*+* +=>>*==*>>*++=> <>>>*=<>>=*><>> ^<^*+*^<^*+*^<^ <<>+=><<>>=+<<>