Matrix and Fibonacci Sum

Time limit5sMemory limit512 MB

Summary
Compute the sum of Fibonacci numbers with linearly growing indices times increasing powers of a K×K matrix, modulo a prime, for N up to 10^1000.
Level

Hard9 of 10

Topics
Matrix, Math, Divide and conquer, Number theory
Solved
No attempts yet

Problem

You are given a K×KK \times K matrix MM and nonnegative integers NN, aa, and dd. Let Mr,cM_{r,c} denote the entry in row rr and column cc of MM.

Define the matrix SS as follows.

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

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

Compute the matrix SS.

Input

The first line contains KK, aa, dd, and NN.

The next KK lines contain the entries of matrix MM. The ii-th of these lines contains Mi,1M_{i,1}, Mi,2M_{i,2}, ..., Mi,KM_{i,K}, separated by spaces.

Output

Print KK lines containing the entries of matrix SS modulo 998244353998244353.

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

Constraints

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

Examples4

  1. Example 1

    Input
    1 0 2 4
    1
    
    Expected output
    33
    
  2. Example 2

    Input
    2 3 4 5
    1 0
    0 1
    
    Expected output
    33552 0
    0 33552
    
  3. Example 3

    Input
    3 23 45 107
    5 7 2
    1 8 9
    3 4 5
    
    Expected output
    601338635 934201293 356700741
    960409891 125261415 197093893
    136328022 287118456 122438416
    
  4. Example 4

    Input
    2 1 1 10000000000
    0 1
    1 998244352
    
    Expected output
    697526667 332697837
    332697837 364828830