Fractal pictures P93774


Statement
 

pdf   zip

Let PP be a rectangular pattern with nn rows and mm columns, where each position is either empty or marked. We can use PP to make nice fractal pictures as follows: Start with a 1×11 \times 1 picture, with its position marked. Then, do kk times: Replace every marked position by PP, and every empty position by an empty n×mn \times m grid. At the end of this process we get an nk×mkn^k \times m^k fractal picture. Here, you will have to print fractal pictures, and also answer some questions about them.

Input

Input consists of several cases separated with blank lines. Each case starts with a line with nn and mm. Then follows PP in nn lines, each with mm characters: ‘.’ for an empty position, ‘X’ for a marked position. Then follows a line with kk, a line with an integer q1q \ge 1, and qq lines, each with a query: every line 1iq1 \le i \le q contains three integers kik_i, rir_i and cic_i. Assume 2n202 \le n \le 20, 2m202 \le m \le 20, nk80n^k \le 80, mk80m^k \le 80, 1rinki10161 \le r_i \le n^{k_i} \le 10^{16}, 1cimki10161 \le c_i \le m^{k_i} \le 10^{16}.

Output

For every test case in the input, print first the nk×mkn^k \times m^k fractal picture that results after applying kk times the pattern PP. Then print a blank line, followed by qq lines, one for each query in the input. For every ii, print the content of the (ri,ci)(r_i, c_i) position after kik_i steps, following the format of the sample output. Print a blank line after the output for every test case.

Public test cases
  • 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
    
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++ Haskell