/* Matrix.cpp
    行列演算用ライブラリ

    verified: AOJ ITP1_7_D Matrix Multiplication
        http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4551007#1
*/
#include <bits/stdc++.h>
using namespace std;

/* Matrix
    + (行列との和): O(N^2)
    - (行列との差): O(N^2)
    * (行列との積): O(N^3)
    * (定数との積): O(N^2)
    pow (行列累乗): O(N^3 log k)
    未完成 det (行列式): O(N^3)
*/
template <typename T>
struct Matrix {
    int N, M;
    vector<vector<T>> A;
    Matrix(int N_) : N(N_), M(N_), A(N_, vector<T>(N_)) {}
    Matrix(int N_, int M_) : N(N_), M(M_), A(N_, vector<T>(M_)) {}
    void init_zeros() {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                A[i][j] = 0;
            }
        }
    }
    void init_ones() {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                A[i][j] = 1;
            }
        }
    }
    void init_I() {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (i != j) {
                    A[i][j] = 0;
                } else {
                    A[i][j] = 1;
                }
            }
        }
    }
    inline const vector<T> &operator[](int k) const {
        return (A.at(k));
    }
    inline vector<T> &operator[](int k) {
        return (A.at(k));
    }
    Matrix &operator+=(const Matrix &B) {
        assert(this->N == B.N && this->M == B.M);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                (*this)[i][j] += B[i][j];
            }
        }
        return (*this);
    }
    Matrix &operator-=(const Matrix &B) {
        assert(this->N == B.N && this->M == B.M);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                (*this)[i][j] -= B[i][j];
            }
        }
        return (*this);
    }
    Matrix &operator*=(const Matrix &B) {
        assert(this->M == B.N);
        int n = this->N;
        int m = B.M;
        int K = this->M;
        Matrix C(n, m);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < K; k++) {
                    C[i][j] += (*this)[i][k] * B[k][j];
                }
            }
        }
        (*this) = C;
        return (*this);
    }
    Matrix &operator*=(const T &x) {
        int n = this->N;
        int m = this->M;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                (*this)[i][j] = (*this)[i][j] * x;
            }
        }
        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 T &x) const { return Matrix(*this) *= x; }
    Matrix pow(long long k) const {
        assert(N == M);
        Matrix ret(N);
        Matrix mul = (*this);
        ret.init_I();
        while (k > 0) {
            if (k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const Matrix &B) {
        int n = B.N;
        int m = B.M;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                os << B[i][j];
                if (j != m - 1) os << " ";
            }
            os << "\n";
        }
        return (os);
    }
    friend istream &operator>>(istream &is, Matrix &B) {
        int n = B.N;
        int m = B.M;
        T t;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                is >> t;
                B[i][j] = t;
            }
        }
        return (is);
    }
};

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main() {
    long long N, K;
    cin >> N >> K;
    Matrix<modint> A(N);
    cin >> A;
    A = A.pow(K);
    modint ans(0);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            ans += A[i][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256