// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;



	

struct Matrix{

  static const int maxn = 105;

  long long int A[maxn][maxn];

  int n;

 

  Matrix(int n_): n(n_) {

    for(int i = 0; i < n; ++i)

      for(int j = 0; j < n; ++j)

        A[i][j] = 0;

  }

 

  Matrix operator * (const Matrix& o) const {

    Matrix ret(n);

    for(int i = 0; i < n; ++i)

      for(int j = 0; j < n; ++j)

        for(int k = 0; k < n; ++k){

          long long int c = A[i][k] * o.A[k][j] % 1000000007;

          ret.A[i][j] = (ret.A[i][j] + c) % 1000000007;

        }

    return ret;

  }

 

  static Matrix identity(int n){

    Matrix ret(n);

    for(int i = 0; i < n; ++i)

      ret.A[i][i] = 1;

    return ret;

  }

 

  Matrix operator ^ (long long k) const {

    Matrix ret = identity(n);

    Matrix a = *this;

    while(k){

      if(k & 1)ret = ret * a;

      a = a * a;

      k /= 2;

    }

    return ret;

  }

 

};



int main(void) {

    long long int N, K;

    cin >> N >> K;

    Matrix matrix(N);

    for(int i=0; i<N; i++) {

        for(int j=0; j<N; j++) {

            cin >> matrix.A[i][j];

        }

    }

    // for(int k=0; k<K-1; k++) {

    //     Matrix matrix_tmp(N, vector<int>(N));

    //     for(int i=0; i<N; i++) {

    //         for(int j=0; j<N; j++) {

    //             for(int l=0; l<N; l++) {

    //                 matrix_tmp[i][j] += matrix[i][l] *matrix[l][j];

    //             }

    //         }

    //     }

    //     matrix = matrix_tmp;

    // }

    // for(int i=0; i<N; i++) {

    //     for(int j=0; j<N; j++) {

    //         cout << matrix[i][j] << " ";

    //     }

    //     cout << endl;

    // }

    matrix = matrix^(K);

    int ans = 0;

    for(int i=0; i<N; i++) {

        for(int j=0; j<N; j++) {

            ans = (ans + matrix.A[i][j]) % 1000000007;

        }

    }

    cout << ans << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.061892778929943x):
#include <bits/stdc++.h>



using namespace std;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>





#define f first

#define s second

#define db long double

#define pb push_back

#define sz(c) (c).size()

#define all(c) (c).begin(),(c).end()



typedef long long ll;

typedef pair <int , int> ii;

typedef pair <ii , int> iii;

typedef vector <int> vi;

typedef vector <ii> vii;

typedef vector <iii> viii;

typedef vector <vi> vvi;

typedef vector <vii> vvii;



const ll mod = 1e9+7;

const int MAXN = 1e4+5;

const int MAXK = 1e2+5;

const db eps = 1e-13;



struct matriz {



    vvi m;

    int SZ;

    matriz( int Sz ) {

        vi v(Sz+1, 0);

        m = vvi( Sz+1, v );

        SZ = Sz;

    }

    matriz( int Sz , int V ) {

        vi v(Sz+1, 0);

        m = vvi( Sz+1, v );

        SZ = Sz;



        for( int i = 0 ; i <= SZ ; i++ )

            m[i][i] = V;

    }

    matriz operator * ( const matriz &X ) const {

        matriz res = matriz( SZ );

        for( int i = 1 ; i <= SZ ; i++ )

            for( int j = 1; j <= SZ ; j++ )

                for( int k = 1; k <= SZ ; k++ )

                    res.m[i][j] = ( res.m[i][j] + ( 1ll * m[i][k] * X.m[k][j] ) % mod ) % mod;

        return res;

    }



};





matriz expMatriz( matriz a , ll b ) {

    matriz res = matriz( a.SZ , 1 );

    while( b ) {



        if( b%2==1 ) {

            res = res*a;

        }

        a = a*a;

        b /= 2;



    }

    return res;

}



int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

    cout<<setprecision(11)<<fixed;



    int n;ll k;

    cin>>n>>k;

    matriz ans = matriz(n);

    for( int i = 1; i <= n ; i++ )

        for( int j = 1; j <= n ; j++ )

            cin>>ans.m[i][j];



    ans = expMatriz( ans , k );

    ll Ans = 0;

    for( int i = 1; i <= n ; i++ )

        for( int j = 1; j <= n ; j++ )

            Ans = ( Ans + ans.m[i][j] ) % mod;



    cout<<Ans<<"\n";



}