import numpy

M=10**9+7

n,k=list(map(int,input().split()))

a=numpy.matrix([list(map(int,input().split()))for i in[0]*n],dtype='O')

b=numpy.eye(n,dtype='O')

while k:

 if k&1:b=b*a%M

 a=a*a%M

 k/=2

print(b.sum()%M)
import numpy as P

M=10**9+7

n,k=list(map(int,input().split()))

a=P.matrix([list(map(int,input().split()))for i in[0]*n],dtype='O')

b=P.eye(n,dtype='O')

while k:

 if k&1:b=b*a%M

 a=a*a%M

 k>>=1

print((b.sum()%M))
import numpy

M = 10**9 + 7
n, k = list(map(int, input().split()))
a = numpy.matrix([list(map(int, input().split())) for i in [0] * n], dtype="O")
b = numpy.eye(n, dtype="O")
while k:
    if k & 1:
        b = b * a % M
    a = a * a % M
    k /= 2
print(b.sum() % M)

import numpy as P

M = 10**9 + 7
n, k = list(map(int, input().split()))
a = P.matrix([list(map(int, input().split())) for i in [0] * n], dtype="O")
b = P.eye(n, dtype="O")
while k:
    if k & 1:
        b = b * a % M
    a = a * a % M
    k >>= 1
print((b.sum() % M))

-import numpy +import numpy as P -a = numpy.matrix([list(map(int, input().split())) for i in [0] * n], dtype="O") -b = numpy.eye(n, dtype="O") +a = P.matrix([list(map(int, input().split())) for i in [0] * n], dtype="O") +b = P.eye(n, dtype="O") -    k /= 2 -print(b.sum() % M) +    k >>= 1 +print((b.sum() % M))