Garbling Game

Time limit1sMemory limit128 MB

Summary
Simulate a periodic matrix-rotation process driven by a garbling map for up to 10^100 turns and count how many times each value is written, modulo 10^5.
Level

Hard8 of 10

Topics
Simulation, Matrix, Math
Solved
No attempts yet

Problem

Pavel invented a game played on a matrix of integers. He starts with an r×cr \times c matrix (rr rows, cc columns) filled with the numbers 11 through rcrc from left to right and top to bottom: 11 sits in the upper-left corner and rcrc in the lower-right corner. Thus the cell in row ii and column jj (both 11-indexed) initially holds the value (i−1)⋅c+j(i-1)\cdot c + j.

He then repeatedly rearranges the matrix and writes a sequence of numbers on a separate sheet; he calls this the garbling of the matrix. The rearrangement is driven by a garbling map: an (r−1)×(c−1)(r-1) \times (c-1) matrix whose entries are the letters L, R, and N.

Pavel plays in a series of turns. The turns visit, in row-major order, every cell that can be the upper-left corner of a 2×22 \times 2 block — that is, every cell except those in the last row or the last column: (1,1),(1,2),…,(1,c−1),(2,1),…,(r−1,c−1)(1,1), (1,2), \dots, (1,c-1), (2,1), \dots, (r-1,c-1). After the (r−1)(c−1)(r-1)(c-1)-th turn he returns to cell (1,1)(1,1) and continues in the same order, so the visited cells repeat with period (r−1)(c−1)(r-1)(c-1).

On each turn Pavel first writes down the number currently stored in the visited cell. He then reads the letter of the garbling map at that same position and rearranges the 2×22 \times 2 block whose upper-left corner is the visited cell:

  • R — the block is rotated one quarter-turn clockwise.
  • L — the block is rotated one quarter-turn counterclockwise.
  • N — the block is left unchanged.

For a block

a b
c d

a clockwise rotation makes it

c a
d b

and a counterclockwise rotation makes it

b d
a c

As an illustration, with the 4×54 \times 5 initial matrix and the garbling map

L R L R
N L L R
L N N L

the first six numbers Pavel writes are 1,7,7,9,1,81, 7, 7, 9, 1, 8 (on the fifth turn the visited cell holds 11 and the map letter is N, so nothing moves).

Given the garbling map and the number of turns nn Pavel makes, determine how many times each number is written down. Because the counts can be large, output each of them modulo 10510^5.

Input

The first line contains three integers rr, cc, and nn, where rr and cc (2≤r,c≤3002 \le r, c \le 300) are the dimensions of the initial matrix and nn (0≤n<101000 \le n < 10^{100}) is the number of turns Pavel makes.

Each of the next r−1r - 1 lines contains c−1c - 1 characters, each R, L, or N, giving one row of the garbling map.

Output

Print rcrc lines. On the ii-th line print the number of times the value ii is written down during Pavel's nn turns, taken modulo 10510^5.

Examples2

  1. Example 1

    Input
    4 5 6
    LRLR
    NLLR
    LNNL
    
    Expected output
    2
    0
    0
    0
    0
    0
    2
    1
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    
  2. Example 2

    Input
    4 5 666666
    LRLR
    NLLR
    LNNL
    
    Expected output
    37038
    37038
    0
    0
    30864
    37036
    11112
    30864
    30864
    30864
    30864
    30864
    11110
    30865
    18519
    30864
    30864
    0
    18518
    18518