Time limit
5s
Memory limit
512 MB
You are given a K×K matrix M and nonnegative integers N, a, and d. Let Mr,c denote the entry in row r and column c of M.
Define the matrix S as follows.
[ S = \sum_{i=0}^{N}{F_{a+i \cdot d} \cdot M^i}. ]
Here, M0 is the identity matrix. The Fibonacci numbers are defined by F0=0, F1=1, and, for i>1, Fi=Fi−1+Fi−2.
Compute the matrix S.
The first line contains K, a, d, and N.
The next K lines contain the entries of matrix M. The i-th of these lines contains Mi,1, Mi,2, ..., Mi,K, separated by spaces.
Print K lines containing the entries of matrix S modulo 998244353.
On the i-th line, print Si,1, Si,2, ..., Si,K separated by spaces.