from numpy import*

M=10**9+7

m=lambda*z:list(map(int,input().split()))

n,k=m()

b=eye(n,n,0,'O')

a=matrix(list(map(m,b)),'O')

while k:b=[b,b*a][k&1];a=a*a%M;k/=2

print(sum(b)%M)
from numpy import*

M=10**9+7

m=lambda*z:list(map(int,input().split()))

n,k=m()

b=[1]*n

a=matrix(list(map(m,b)),'O')

while k:b*=[1,a][k&1];a=a*a%M;k/=2

print(sum(b)%M)
from numpy import *

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

from numpy import *

M = 10**9 + 7
m = lambda *z: list(map(int, input().split()))
n, k = m()
b = [1] * n
a = matrix(list(map(m, b)), "O")
while k:
    b *= [1, a][k & 1]
    a = a * a % M
    k /= 2
print(sum(b) % M)

-b = eye(n, n, 0, "O") +b = [1] * n -    b = [b, b * a][k & 1] +    b *= [1, a][k & 1]