#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=50+5, mod=1e9+7;
ll n,k;
struct mat {
    ll val[maxn][maxn];
    mat(){ memset(val, 0, sizeof(val)); }
    ll* operator[] (ll i) {return val[i];}
} ady;
void mat_mul(mat &a, mat &b) {
    mat c;
    rep(i,0,n)
        rep(j,0,n)
            rep(k,0,n)
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;
    memcpy(&a,&c,sizeof a);
}
void mat_exp(mat &a, ll x) {
    mat b; rep(i,0,n) b[i][i]=1;
    for(;x;x/=2,mat_mul(a,a)) if(x&1) mat_mul(b,a);
    memcpy(&a,&b,sizeof a);
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    rep(i,0,n) rep(j,0,n) cin>>ady[i][j];
    mat_exp(ady, k);
    ll ans=0; rep(i,0,n) rep(j,0,n) ans=(ans+ady[i][j])%mod;
    cout<<ans<<"\n";
}
