#include "bits/stdc++.h"
 
using namespace std;
 
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
 
 
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
 
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;
 
const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;
 
int arr[NMAX];
int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<int> v;
typedef long long ll;
 
template <typename T, int N>
void multiply(T A[N][N], T B[N][N]) {
    T C[N][N]={0};
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N ;k++) {
                (C[i][j] += (A[i][k]*B[k][j]) % MOD);
                C[i][j] %= MOD;
                if (C[i][j] >= MOD) C[i][j] -= MOD;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            A[i][j] = C[i][j];
        }
    }
    // cout<<N;
}
 
template <typename T, int N>
void power(T A[N][N], T base[N][N], int k) {
    // cout<<"here";
    if (k == 0) return; // assumes A is I initially
    else {
        power(A, base, k/2);
        multiply<T, N>(A, A);
        if (k & 1LL) {
            multiply<T, N>(A, base);
        }
    }
}
 
template<typename T, int N>
void solve(T transition[N][N], ll k) {
    T r[N][N]={0};
    for (int i = 0; i < N; i++) r[i][i]=1; // r is I
 
    power<T, N>(r, transition, k);
 
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            transition[i][j] = r[i][j];
        }
    }
    // for (int i = 0; i < N; i++) {
    //     next[i]=0;
    //     for (int j = 0; j < N; j++) {
    //         (next[i] += (r[i][j]*cur[j]) % MOD);
    //         next[i] %= MOD;
    //         if (next[i] >= MOD) next[i] -= MOD;
    //     }
    // }
}
 
/* Sample Use */
 
// int32_t main() {
//     int A[2][2] = {{1, 1}, {1, 0}};
//     int cur[2] = {1, 0}, next[2];
//     int k;
//     cin >> k;
//     solve(A, cur, k, next);
//     cout << next[1] << endl;
// }
 
void solve()
{
    cin>>n>>k;
 
    int A[100][100]={0};
 
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            A[i][j] = 0;
        }
    }
 
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>A[i][j];
        }
    }
    // cout<<k<<" ";
    solve(A,k);
 
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            // tr(i,j,A[i][j]);
            ans += A[i][j];
            ans %= MOD;
        }
    }

    // cout<<A[0][n-1]<<"\n";
    cout<<ans;
}
 
int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 640