import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone {
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in); int n, m;
m = sc.nextInt();
n = sc.nextInt();
double [][] a = new double [m][m];
double [][] b = new double [m][m];
double [][] c = new double [m][m];
double [][] ans = new double [m][m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextDouble();
c[i][j] = b[i][j] = ans[i][j] = a[i][j];
}
}
for (int it = 1; it < n; it++) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
c[i][j] = 0;
for (int k = 0; k < m; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
ans[i][j] += c[i][j];
b[i][j] = c[i][j];
}
}
}
for (int i = 0; i < m; i++) {
ans[i][i]++;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
System.
out.
print(ans
[i
][j
] + " "); }
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBJZGVvbmUgewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHsKCQlTY2FubmVyIHNjID0gbmV3IFNjYW5uZXIgKFN5c3RlbS5pbik7CgkJaW50IG4sIG07CgkJbSA9IHNjLm5leHRJbnQoKTsKCQluID0gc2MubmV4dEludCgpOwoJCWRvdWJsZSBbXVtdIGEgPSBuZXcgZG91YmxlIFttXVttXTsKCQlkb3VibGUgW11bXSBiID0gbmV3IGRvdWJsZSBbbV1bbV07CgkJZG91YmxlIFtdW10gYyA9IG5ldyBkb3VibGUgW21dW21dOwoJCWRvdWJsZSBbXVtdIGFucyA9IG5ldyBkb3VibGUgW21dW21dOwoJCWZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CgkJCWZvciAoaW50IGogPSAwOyBqIDwgbTsgaisrKSB7C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