#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 114;
const ll M = 1e9 + 7;
int n;
ll k;
class Matrix
{
public:
int l;
ll m[N][N];
Matrix()
{
memset(m, 0, sizeof(m));
}
Matrix(int l)
{
this->l = l;
memset(m, 0, sizeof(m));
}
void init()
{
memset(m, 0, sizeof(m));
for(int x = 1; x <= l; x++) m[x][x] = 1;
}
Matrix operator*(const Matrix &m2)
{
Matrix res(l);
for(int x = 1; x <= l; x++) for(int y = 1; y <= l; y++) for(int z = 1; z <= l; z++) res.m[x][y] = (res.m[x][y] + m[x][z] * m2.m[z][y] % M) % M;
return res;
}
Matrix operator^(ll p_)
{
Matrix base = *(this), res(l);
res.init();
while(p_)
{
if(p_ & 1) res = res * base;
base = base * base;
p_ >>= 1;
}
return res;
}
void input(int l)
{
this->l = l;
for(int x = 1; x <= l; x++) for(int y = 1; y <= l; y++) scanf("%lld", &m[x][y]);
}
void output()
{
for(int x = 1; x <= l; x++)
{
for(int y = 1; y <= l; y++) printf("%lld ", m[x][y]);
printf("\n");
}
}
}a, b;
int main()
{
scanf("%d %d", &n, &k);
a.input(n);
(a ^ k).output();
return 0;
}
record