Sum of Matrix Powers

Given an N by N matrix A and K, compute A + A^2 + ... + A^K with all entries reduced modulo M.

Medium7Divide and conquerMatrixMathNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given an N×NN \times N matrix AA and integers KK and MM. Reducing every entry of AKA^K modulo MM is not hard.

This task asks for something else. Define the matrix SS as

S=A+A2+A3++AKS = A + A^2 + A^3 + \cdots + A^K

and print every entry of SS modulo MM.

Input

The first line contains NN, KK, and MM separated by spaces (1N501 \le N \le 50, 1K1091 \le K \le 10^9, 1M1041 \le M \le 10^4).

Each of the next NN lines contains the matrix AA, NN integers per line separated by spaces (104Aij104-10^4 \le A_{ij} \le 10^4).

Output

Print NN lines. Each line holds the NN entries of the corresponding row of SS reduced modulo MM, separated by single spaces.

Hint

Every remainder must be at least 00 and less than MM. Entries of AA can be negative, so watch the sign of the remainder.