#include <cstdio>
#include <cctype>
typedef long long int int64;
const int mod = 1000000007;
int n, k;
int64 mat[105][105], mans[105][105], ans[105][105];
int getint()
{
register int x = 0;
register char ch = 0;
char f = 0;
while (!isdigit(ch)) f = (ch == '-'), ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 0x30), ch = getchar();
return f ? -x : x;
}
void mul(int64 m1[][105], int64 m2[][105])
{
for (register int i = 1; i <= n; i++)
for (register int j = 1; j <= n; j++)
mans[i][j] = 0;
for (register int i = 1; i <= n; i++)
for (register int j = 1; j <= n; j++)
for (register int k = 1; k <= n; k++)
mans[i][j] = (mans[i][j] + m1[i][k] * m2[k][j]) % mod;
}
void cpy(int64 dest[][105], int64 src[][105])
{
for (register int i = 1; i <= n; i++)
for (register int j = 1; j <= n; j++)
dest[i][j] = src[i][j];
}
void qpow(int64 m[][105])
{
for (register int i = 1; i <= n; i++) ans[i][i] = 1;
while (k) {
if (k & 1) {
mul(ans, m);
cpy(ans, mans);
}
mul(m, m);
cpy(m, mans);
k >>= 1;
}
}
int main()
{
n = getint(); k = getint();
for (register int i = 1; i <= n; i++)
for (register int j = 1; j <= n; j++)
mat[i][j] = getint();
qpow(mat);
for (register int i = 1; i <= n; i++) {
for (register int j = 1; j <= n; j++)
printf("%lld ", ans[i][j]);
putchar('\n');
}
return 0;
}