// Slower C++ solution:
//#include <boost/multiprecision/cpp_dec_float.hpp>

//#include <boost/multiprecision/cpp_int.hpp>

#include <stdio.h>

#include <iostream>

#include <vector>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <math.h>

#include <algorithm>

#include <bitset>

#include <iomanip>

using namespace std;

//namespace mp = boost::multiprecision;

//using llll = mp::cpp_int;

// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

//using Real = mp::number<mp::cpp_dec_float<1024>>;

using ll = long long;

const double EPS = 1e-10;

const ll MOD = 7+(1e+9);





ll N , M;



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;

  M=n;

  N=k;

  Matrix a(M);

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

    for(ll j=0;j<M;j++){

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

    }

  }

  a = a ^ (N);

  ll ret = 0;

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

    for(ll j=0;j<M;j++){

      ret=(ret+a.A[i][j])%MOD;

    }

  }

  cout << ret << endl;

}


// Faster C++ solution for the same problem (measured speedup: 3.1430341046265946x):
//#pragma GCC target ("avx2,sse2")

//#pragma GCC optimization ("Ofast")

//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



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

#define ll long long

#define ull unsigned long long

#define db double

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define fi first

#define se second

#define mp make_pair

#define up_b upper_bound

#define low_b lower_bound

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

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

#define endl "\n"



#define left fsdsdfoisf

#define sum dpsdfioppsf

#define assign xcvjlkdjfio

#define trie fksdfkjkfnjuiv

#define next sidlfjsfkl

#define merge sdfksdkfsldf



//#define int long long



using namespace std;



void dout() {

    cerr << endl;

}

template <typename Head, typename... Tail>

void dout(Head H, Tail... T) {

    cerr << H << ' ';

    dout(T...);

}



//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair <int, int> pii;



const int N = 53, MOD = 1e9 + 7;

int n;

ll k;



struct Mat {

    int a[N][N];

    Mat() {

        memset(a, 0, sizeof(a));

    }

    void one() {

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

            a[i][i] = 1;

        }

    }

    Mat operator * (const Mat & m) const {

        Mat res;

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

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

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

                    res.a[i][k] += (ll)a[i][j] * m.a[j][k] % MOD;

                    if (res.a[i][k] >= MOD) {

                        res.a[i][k] -= MOD;

                    }

                }

            }

        }

        return res;

    }

    Mat binpow(ll x) {

        Mat res, num = * this;

        res.one();

        while (x > 0) {

            if (x & 1) {

                res = res * num;

            }

            x /= 2;

            num = num * num;

        }

        return res;

    }

};



void solve(int tc) {

    // check for (int i = 0; i < n; j++)

    cin >> n >> k;

    Mat m;

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

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

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

        }

    }

    m = m.binpow(k);

    int res = 0;

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

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

            res += m.a[i][j];

            if (res >= MOD) {

                res -= MOD;

            }

        }

    }

    cout << res;

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    int tc = 1;

//    cin >> tc;

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

        solve(i);

//        cleanup();

    }

}