Bobo invents a new series of matrices M_0,M_1,…M_n defined as follows:
Given m×m matrices A,B and integers c_1,c_2,…,c_n, compute M_n under Z_mod (that is, addition and multiplication of numbers are carried out modulo mod).
The input contains zero or more test cases, and is terminated by end-of-file. For each test case:
The first line contains three integers n, m and mod (1≤n≤106, 1≤m≤5, 2≤mod≤109).
The i-th of the next m lines contains m integers A_i,1,A_i,2,…,A_i,m, and the i-th of the following m lines contains m integers B_i,1,B_i,2,…,B_i,m (0≤A_i,j,B_i,j<mod).
The last line contains n integers c_1,c_2,…,c_n (0≤c_i<i, c_1≤c_2≤⋯≤c_n).
It is guaranteed that the sum of n does not exceed 106.
For each test case, output m lines. On the i-th line, output m integers C_i,1,C_i,2,…,C_i,m where C_i,j=M_n,i,j.