#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int N = 1e9 + 7;
int n;
struct __________ {
LL _____[0x7f][0x7f];
};
__________ operator * (__________& A, __________& B) {
__________ _____;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 1; k <= n; ++k)
_____._____[i][j] = (_____._____[i][j] + A._____[i][k] * B._____[k][j]) % N;
return _____;
}
__________ power(__________& A, LL n) {
if(n == 1) return A;
__________ _____ = power(A, n / 2);
_____ = _____ * _____;
if(n % 2) _____ = _____ * A;
return _____;
}
LL k;
__________ A;
int main() {
cin >> n >> k;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
cin >> A._____[i][j];
if(k == 0) {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j)
(i == j) ? cout << "1 " : cout << "0 ";
cout << '\n';
}
return 0;
}
A = power(A, k);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j)
cout << A._____[i][j] << ' ';
cout << '\n';
}
return 0;
}