Let be a rectangular pattern with rows and columns, where each position is either empty or marked. We can use to make nice fractal pictures as follows: Start with a picture, with its position marked. Then, do times: Replace every marked position by , and every empty position by an empty grid. At the end of this process we get an fractal picture. Here, you will have to print fractal pictures, and also answer some questions about them.
Input consists of several cases separated with blank lines. Each case
starts with a line
with
and
.
Then follows
in
lines, each with
characters: ‘.’ for an empty position, ‘X’ for
a marked position. Then follows a line with
,
a line with an integer
,
and
lines, each with a query: every line
contains three integers
,
and
.
Assume
,
,
,
,
,
.
For every test case in the input, print first the fractal picture that results after applying times the pattern . Then print a blank line, followed by lines, one for each query in the input. For every , print the content of the position after steps, following the format of the sample output. Print a blank line after the output for every test case.
Input
3 3 .X. XXX .X. 3 2 3 1 14 3 1 15 2 3 ..X XXX 2 4 2 1 1 2 1 9 2 4 1 0 1 1 2 2 .X XX 3 1 50 1125899906842624 1125899906842624
Output
.............X............. ............XXX............ .............X............. ..........X..X..X.......... .........XXXXXXXXX......... ..........X..X..X.......... .............X............. ............XXX............ .............X............. ....X........X........X.... ...XXX......XXX......XXX... ....X........X........X.... .X..X..X..X..X..X..X..X..X. XXXXXXXXXXXXXXXXXXXXXXXXXXX .X..X..X..X..X..X..X..X..X. ....X........X........X.... ...XXX......XXX......XXX... ....X........X........X.... .............X............. ............XXX............ .............X............. ..........X..X..X.......... .........XXXXXXXXX......... ..........X..X..X.......... .............X............. ............XXX............ .............X............. after 3 step(s), (1, 14) is marked after 3 step(s), (1, 15) is empty ........X ......XXX ..X..X..X XXXXXXXXX after 2 step(s), (1, 1) is empty after 2 step(s), (1, 9) is marked after 2 step(s), (4, 1) is marked after 0 step(s), (1, 1) is marked .......X ......XX .....X.X ....XXXX ...X...X ..XX..XX .X.X.X.X XXXXXXXX after 50 step(s), (1125899906842624, 1125899906842624) is marked