#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const ll mod=1e9+7;
ll n,m;
struct matrix //自己*x -> res
{
ll a[105][105];
matrix operator * (const matrix &x) const
{
matrix res;
fo(i,1,n)
fo(j,1,n)
{
res.a[i][j]=0;
fo(k,1,n)
res.a[i][j]=(res.a[i][j]+a[i][k]*x.a[k][j])%mod;
}
return res;
}
}x,ans;
int main()
{
scanf("%lld%lld",&n,&m);
fo(i,1,n)
fo(j,1,n)
scanf("%lld",&x.a[i][j]);
ans=x,m--;
while(m)
{
while((m&1)==0) x=x*x,m>>=1;
ans=ans*x;
m>>=1,x=x*x;
}
fo(i,1,n)
{
fo(j,1,n)
printf("%lld ",ans.a[i][j]);
cout<<endl;
}
return 0;
}