#include <iostream>
using namespace std;
struct matrix {
    int data[10][10];
    int row;
    int col;
    matrix(int r) {
        row = col = r;
    }
    matrix operator* (matrix B);
};
matrix matrix::operator* (matrix B) {
    matrix ans(row);
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            ans.data[i][j]=0;
            for (int k = 0; k < row; k++) {
                ans.data[i][j] += data[i][k] * B.data[k][j];
            }
        }
    }
    return ans;
}
void print(matrix A) {
    for (int i = 0; i < A.row; i++) {
        for (int j = 0; j < A.col; j++) {
            cout << A.data[i][j];
            if (j == A.col - 1) cout << endl;
            else cout << ' ';
        }
    }
}
int main() {
    int n, k;
    while (cin >> n >> k) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        matrix A = matrix(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int temp;
                cin >> temp;
                A.data[i][j] = temp;
            }
        }
        matrix ans=matrix(n);
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j) ans.data[i][j]=1;
                else ans.data[i][j]=0;
            }
        }
        for(int i=0;i<k;i++){
            ans=ans*A;
        }
        print(ans);
    }
}
// 64 位输出请用 printf("%lld")