#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
template <class T>
struct Matrix {
    vector<vector<T>> mat;
    int row, col;

    Matrix(int r, int c, T v = 0) : mat(r, vector<T>(c, v)), row(r), col(c){};

    inline const vector<T> &operator[](int k) const { return mat[k]; }
    inline vector<T> &operator[](int k) { return mat[k]; }

    Matrix &operator+=(const Matrix &A) {
        for (int i = 0; i < row; i++)
            for (int j = 0; j < col; j++)
                ((*this)[i][j] += A[i][j]) %= MOD;
        return (*this);
    }

    Matrix &operator-=(const Matrix &A) {
        for (int i = 0; i < row; i++)
            for (int j = 0; j < col; j++)
                (*this)[i][j] -= A[i][j];
        return (*this);
    }

    Matrix &operator*=(const Matrix &A) {
        vector<vector<T>> res(row, vector<T>(A.col, 0));
        for (int i = 0; i < row; i++)
            for (int j = 0; j < A.col; j++)
                for (int k = 0; k < col; k++)
                    (res[i][j] += mat[i][k] * A[k][j]) %= MOD;
        mat.swap(res);
        (*this).col = A.col;
        return (*this);
    }

    Matrix &operator^=(long long p) {
        Matrix res = Matrix(row, col);
        for (int i = 0; i < row; i++) res[i][i] = 1;
        
        while(p > 0){
            if (p & 1) res *= *this;
            *this *= *this;
            p >>= 1;
        }
        mat.swap(res.mat);
        return (*this);
    }

    Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
    Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
    Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
    Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); }

    friend ostream &operator<<(ostream &os, Matrix &p) {
        for (int i = 0; i < p.row; i++) {
            os << "[";
            for (int j = 0; j < p.col; j++) {
                os << p[i][j] << (j + 1 == p.col ? "]\n" : ",");
            }
        }
        return (os);
    }
};

int main() {
    init();
    ll N, K;
    cin >> N >> K;

    Matrix<ll> G(N, N), I(N, 1, 1);
    rep(i, N)rep(j, N){
        cin >> G.mat[i][j];
    }
    

    G ^= K;

    Matrix<ll> A = G * I;


    ll ans = 0;
    rep(i, N) ans += A.mat[i][0];
    cout << ans % MOD << endl;
}

Measured memory_bytes: 3700