def get_changeList(numList, size):
list1 = [[0 for _ in range(size)] for _ in range(size)]
for i in range(size):
for j in range(size):
list1[i][j] = numList[j][i]
return list1
def get_newList(numList, list1, size):
newList = [[0 for _ in range(size)] for _ in range(size)]
for i in range(size):
for j in range(size):
newList[i][j] = sum([numList[i][k] * list1[j][k] for k in range(size)])
return newList
if __name__ == '__main__':
alls = input().split(" ")
size = int(alls[0])
times = int(alls[1])
numList = [[int(i) for i in input().split(" ")] for _ in range(size)]
list1 = [[0 for _ in range(size)] for _ in range(size)]
for _ in range(times - 1):
list1 = get_changeList(numList, size)
numList = get_newList(numList, list1, size)
print(numList)