cho.sh
Notes
Loading...

Matrix and Fibonacci Sum

Time limit

5s

Memory limit

512 MB

Problem

You are given a K×KK \times KK×K matrix MMM and nonnegative integers NNN, aaa, and ddd. Let Mr,cM_{r,c}Mr,c​ denote the entry in row rrr and column ccc of MMM.

Define the matrix SSS as follows.

[ S = \sum_{i=0}^{N}{F_{a+i \cdot d} \cdot M^i}. ]

Here, M0M^0M0 is the identity matrix. The Fibonacci numbers are defined by F0=0F_0 = 0F0​=0, F1=1F_1 = 1F1​=1, and, for i>1i > 1i>1, Fi=Fi−1+Fi−2F_i = F_{i-1} + F_{i-2}Fi​=Fi−1​+Fi−2​.

Compute the matrix SSS.

Input

The first line contains KKK, aaa, ddd, and NNN.

The next KKK lines contain the entries of matrix MMM. The iii-th of these lines contains Mi,1M_{i,1}Mi,1​, Mi,2M_{i,2}Mi,2​, ..., Mi,KM_{i,K}Mi,K​, separated by spaces.

Output

Print KKK lines containing the entries of matrix SSS modulo 998244353998244353998244353.

On the iii-th line, print Si,1S_{i,1}Si,1​, Si,2S_{i,2}Si,2​, ..., Si,KS_{i,K}Si,K​ separated by spaces.

Constraints

  • 1≤K≤1001 \le K \le 1001≤K≤100
  • 0≤a,d≤1090 \le a, d \le 10^90≤a,d≤109
  • 0≤N≤1010000 \le N \le 10^{1000}0≤N≤101000
  • 0≤Mi,j<9982443530 \le M_{i,j} < 9982443530≤Mi,j​<998244353