// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define V vector<long long>

#define VV vector<vector<long long>>

#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))

using namespace std;



struct suffix_array{



    int n,logn;

    vector<int> rank,sa;



    suffix_array(string s){

        n=s.size();

        logn=floor(log2(n));

        rank.resize(n);

        sa.resize(n);

        rep(i,n){

            rank[i]=s[i];

            sa[i]=i;

        }

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

            auto comp=[&](int a,int b){

                if(rank[a]!=rank[b])return rank[a]<rank[b];

                a=(a+(1<<k)<n)?rank[a+(1<<k)]:-1;

                b=(b+(1<<k)<n)?rank[b+(1<<k)]:-1;

                return a<b;

            };

            sort(sa.begin(),sa.end(),comp);

            vector<int> tmp=rank;

            tmp[sa[0]]=0;

            for(int i=1;i<n;++i)tmp[sa[i]]=tmp[sa[i-1]]+comp(sa[i-1],sa[i]);

            rank=tmp;

        }

    }



    int operator[](int k)const{

        return sa[k];

    }



    int size()const{

        return n;

    }



};



const ll mod = 1e9+7;



struct Matrix{

  static const int maxn = 105;

  ll 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){

          ll c = A[i][k] * o.A[k][j] % mod;

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

        }

    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(){

    ll n,k;

    cin>>n>>k;

    Matrix M(n);

    rep(i,n){

        rep(j,n){

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

        }

    }

    M=M^k;

    ll ans=0;

    rep(i,n){

        rep(j,n){

            ans+=M.A[j][i];

            ans%=mod;

        }

    }

    cout<<ans<<endl;

}


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

#define f first

#define s second

#define pb push_back

#define ENDL '\n'

#define all(a) begin(a),end(a)

#define sz(a) (int)(a.size())

#define deb(a) cout << #a << ": " << a << ENDL

#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)

#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



using namespace std;



typedef long long lli;

typedef long double ld;

typedef pair<lli, lli> ii;

typedef vector<lli> vi;





lli MOD = 1e9 + 7;



vector<vector<lli>> ones(int n) {

	vector<vector<lli>> identity(n, vector<lli>(n));

	fore(i, 0, n) identity[i][i] = 1;

	return identity;

}

vector<vector<lli>> operator*(vector<vector<lli>> &u, vector<vector<lli>> &v) {

    int n = sz(u);

	vector<vector<lli>> ans(n, vector<lli>(n));

	fore(i, 0 ,n) fore(j, 0, n) fore(k, 0, n)

        ans[i][j] = (ans[i][j] + (u[i][k] * v[k][j])) % MOD;

	return ans;

}

vector<vector<lli>> pot(vector<vector<lli>> mat, lli exp) {

	vector<vector<lli>> res = ones(sz(mat));

	while(exp) {

        if(exp % 2) res = res * mat;

        mat = mat * mat;

        exp /= 2;

	}

	return res;

}



int main()

{   _

    lli n, k; cin >> n >> k;

    vector<vector<lli>> m(n, vector<lli>(n));

    fore(i, 0, n) fore(j, 0, n) cin >> m[i][j];

    vector<vector<lli>> res = pot(m, k);

    lli ans = 0;

    for(auto itt : res) for(auto it : itt) ans = (ans + it) % MOD;

    cout << ans << ENDL;

    return 0;

}