#include <iostream>
using namespace std;
const int maxn=10;
struct matrix{
int digit[maxn][maxn];
int col;
int row;
matrix(int a,int b){
row=a;
col=b;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
digit[i][j]=0;
}
}
}
};
void inputmatrix(matrix& x){
for(int i=0;i<x.row;i++){
for(int j=0;j<x.col;j++){
cin>>x.digit[i][j];
}
}
}
matrix mulmatrix(matrix a,matrix b){
matrix c(a.row,b.col);
for(int i=0;i<a.row;i++){
for(int j=0;j<b.col;j++){
for(int k=0;k<a.col;k++){
c.digit[i][j]+=a.digit[i][k]*b.digit[k][j];
}
}
}
return c;
}
matrix produceEye(int n){
matrix x(n,n);
for(int i=0;i<x.row;i++){
x.digit[i][i]=1;
}
return x;
}
void outpmatrix(matrix a){
for(int i=0;i<a.row;i++){
for(int j=0;j<a.col;j++){
cout<<a.digit[i][j]<<" ";
}
cout<<endl;
}
}
int main() {
int n,k;
while (cin>>n>>k) {
matrix a(n,n);
inputmatrix(a);
matrix x=produceEye(n);
while(k>0){
if(k%2==1){
x=mulmatrix(x, a);
}
k/=2;
a=mulmatrix(a, a);
}
outpmatrix(x);
}
}