// template {{{
#include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

template<typename T>
class matrix {
    private:
    size_t N, M;
    T *values;

    void allocate_memory(size_t _N, size_t _M) {
        values = new T[_N*_M];
    }

    public:
    matrix(size_t _N, size_t _M):
        N(_N), M(_M) {
            allocate_memory(_N, _M);
        }

    matrix(initializer_list<vector<T>> list) {
        N = list.size(); M = list.begin()->size();
        allocate_memory(N, M);
        size_t index = 0;
        for (const vector<T> &v: list) {
            for (const T &x: v) {
                this->values[index] = x;
                index++;
            }
        }
    }

    matrix(vector<vector<T>> list) {
        N = list.size(); M = list.begin()->size();
        allocate_memory(N, M);
        size_t index = 0;
        for (const vector<T> &v: list) {
            for (const T &x: v) {
                this->values[index] = x;
                index++;
            }
        }
    }

    matrix(const matrix& other):
        N(other.N), M(other.M) {
            allocate_memory(N, M);
            memcpy(values, other.values, N*M*sizeof(*values));
    }

    void set_identity() {
        assert(N == M);
        memset(values, 0, N*M*sizeof(*values));
        for (int i = 0; i < N; i++) {
            values[i*M+i] = 1;
        }
    }

    T* operator[](const size_t index) const {
        return values + index * M;
    }

    matrix& operator=(const matrix& other) {
        delete[] values;

        allocate_memory(N, M);
        memcpy(values, other.values, N*M*sizeof(*values));

        return *this;
    }

    matrix operator*(const matrix& other) const {
        assert(M == other.N);
        matrix ret(N, other.M);
        for (size_t i = 0; i < N; i++) {
            for (size_t j = 0; j < other.M; j++) {
                ret[i][j] = 0;
                for (size_t k = 0; k < M; k++) {
                    ret[i][j] += (*this)[i][k] * other[k][j];
                    ret[i][j] %= MOD;
                }
            }
        }
        return ret;
    }

    matrix& operator*=(const matrix &other) {
        return *this = *this * other;
    }

    matrix operator^(long long power) const {
        assert(N == M);
        matrix ret(N, M), base = *this;
        ret.set_identity();
        while (power > 0) {
            if (power % 2) ret *= base;
            power /= 2;
            base *= base;
        }
        return ret;
    }
};

void solve()
{
    int n; ll k; cin >> n >> k;
    vector<vector<ll>> v(n, vector<ll>(n));
    vector<vector<ll>> a(1, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> v[i][j];
        }
        a[0][i] = 1;
    }
    matrix<ll> mat(v), ans(a);
    mat = mat ^ k;
    /* for (int i = 0; i < n; i++) { */
    /*     for (int j = 0; j < n; j++) { */
    /*         cout << mat[i][j] << " "; */
    /*     } */
    /*     cout << endl; */
    /* } */
    ans = ans * mat;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        /* cout << ans[0][i] << endl; */
        sum += ans[0][i];
        sum %= MOD;
    }
    cout << sum << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 2688