#include <bits/stdc++.h>
using namespace std;
const int N=110,mod=1000000007;
typedef long long LL;
inline LL read() {
LL x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
}
while('0'<=ch && ch<='9') {
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int n,k;
struct Xr {
LL val[N][N];
void build() {
for(int i=1; i<=n; i++) val[i][i]=1;
}
void in() {
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
val[i][j]=read();
}
void output() {
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) printf("%lld ",val[i][j]);
printf("\n");
}
}
}Original;
Xr operator *(const Xr &x,const Xr &y) {
Xr z;
for(int l=1; l<=n; l++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
z.val[i][j]=(z.val[i][j]+x.val[i][l]*y.val[l][j])%mod;
return z;
}
Xr quickpow(Xr d,int z) {
if(z==1) return d;
Xr tmp=quickpow(d,z/2);
if(z%2==1) return (tmp*tmp)*d;
else return tmp*tmp;
}
int main() {
scanf("%d%d",&n,&k);
Original.in();
quickpow(Original,k).output();
return 0;
}
MLE+WA求助