#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;
template<int MOD = 1000000007>

struct mod_int {
    int val;
    mod_int(long long val_ = 0) : val(val_ % MOD) { if (val < 0) { val += MOD; }}
    bool operator==(const mod_int &rhs) const { return val == rhs.val; }
    bool operator!=(const mod_int &rhs) const { return std::rel_ops::operator!=(*this, rhs); }
    mod_int &operator+=(const mod_int &rhs) {
        if ((val += rhs.val) >= MOD) { val -= MOD; }
        return *this;
    }
    mod_int &operator-=(const mod_int &rhs) {
        if ((val += MOD - rhs.val) >= MOD) { val -= MOD; }
        return *this;
    }
    mod_int &operator*=(const mod_int &rhs) {
        val = (int) ((long long) val * rhs.val % MOD);
        return *this;
    }
    mod_int &operator/=(const mod_int &rhs) { return *this *= rhs.inv(); }
    mod_int operator+() const { return *this; }
    mod_int operator-() const { return -val; }
    mod_int operator++() { return *this += 1; }
    mod_int operator--() { return *this -= 1; }
    mod_int operator++(signed) {
        const mod_int ret(*this);
        ++*this;
        return ret;
    }
    mod_int operator--(signed) {
        const mod_int ret(*this);
        --*this;
        return ret;
    }
    mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
    mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
    mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
    mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
    mod_int inv() const {
        assert(val != 0);
        int a = val, b = MOD, x = 1, u = 0;
        while (b) {
            int t = a / b;
            std::swap(a -= t * b, b);
            std::swap(x -= t * u, u);
        }
        return x;
    }
    mod_int pow(long long n) const {
        if (n < 0) { return pow(-n).inv(); }
        mod_int ret = 1, mul = *this;
        while (n) {
            if (n & 1) { ret *= mul; }
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend std::istream &operator>>(std::istream &is, mod_int &rhs) {
        long long v;
        is >> v;
        rhs = v;
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const mod_int &rhs) { return os << rhs.val; }
    struct combination {
        std::vector<mod_int> fact{1, 1}, f_inv{1, 1}, inv{0, 1};
        void calc(int n) {
            while (fact.size() <= n) {
                int i = fact.size();
                fact.push_back(fact[i - 1] * i);
                inv.push_back(-inv[MOD % i] * (MOD / i));
                f_inv.push_back(f_inv[i - 1] * inv[i]);
            }
        }
        mod_int P(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[n - r]); }
        mod_int C(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[r] * f_inv[n - r]); }
        mod_int H(int n, int r) { return C(n + r - 1, r); }
    };
};

using mint = mod_int<>;

template<typename M>
struct matrix {
    using T = typename M::T;
    int h, w;
    std::vector<std::vector<T>> data;
    matrix(int h, int w) : h(h), w(w), data(h, std::vector<T>(w, M::id_pl())) {}
    matrix(const std::vector<std::vector<T>> &src) : h(src.size()), w(src[0].size()), data(src) {}
    std::vector<T> &operator[](int i) { return data[i]; }
    const std::vector<T> &operator[](int i) const { return data[i]; }
    static matrix identity(int n) {
        matrix ret(n, n);
        for (int i = 0; i < n; i++) { ret[i][i] = M::id_cr(); }
        return ret;
    }
    bool operator==(const matrix &rhs) const {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (data[i][j] != rhs[i][j]) { return false; }
            }
        }
        return true;
    }
    bool operator!=(const matrix &rhs) const { return std::rel_ops::operator!=(*this, rhs); }
    matrix &operator+=(const matrix &rhs) {
        assert(h == rhs.h && w == rhs.w);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                (*this)[i][j] = M::pl((*this)[i][j], rhs[i][j]);
            }
        }
        return *this;
    }
    matrix &operator-=(const matrix &rhs) {
        assert(h == rhs.h && w == rhs.w);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                (*this)[i][j] = M::pl((*this)[i][j], M::inv_pl(rhs[i][j]));
            }
        }
        return *this;
    }
    matrix &operator*=(const matrix &rhs) {
        assert(w == rhs.h);
        std::vector<std::vector<T>> ret(h, std::vector<T>(rhs.w, M::id_pl()));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < rhs.w; j++) {
                for (int k = 0; k < w; k++) {
                    ret[i][j] = M::pl(ret[i][j], M::cr((*this)[i][k], rhs[k][j]));
                }
            }
        }
        data = ret;
        h = data.size(), w = data[0].size();
        return *this;
    }
    matrix &operator/=(const matrix &rhs) { return *this *= rhs.inv(); }
    matrix operator+() const { return *this; }
    matrix operator-() const { return matrix(h, w) -= *this; }
    matrix operator+(const matrix &rhs) const { return matrix(*this) += rhs; }
    matrix operator-(const matrix &rhs) const { return matrix(*this) -= rhs; }
    matrix operator*(const matrix &rhs) const { return matrix(*this) *= rhs; }
    matrix operator/(const matrix &rhs) const { return matrix(*this) /= rhs; }
    matrix inv() const {
        assert(h == w);
        matrix id = identity(h);
        std::vector<std::vector<T>> ex(h, std::vector<T>(w << 1));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) { ex[i][j] = (*this)[i][j]; }
            for (int j = 0; j < w; j++) { ex[i][w + j] = id[i][j]; }
        }
        for (int i = 0; i < h; i++) {
            for (int j = i; j < w; j++) {
                if (!M::is_id_pl(ex[i][j])) {
                    swap(ex[i], ex[j]);
                    break;
                }
            }
            if (M::is_id_pl(ex[i][i])) { return matrix(0, 0); }
            T inv = M::inv_cr(ex[i][i]);
            for (int j = i + 1; j < w << 1; j++) { ex[i][j] = M::cr(ex[i][j], inv); }
            for (int j = i + 1; j < h; j++) {
                for (int k = i + 1; k < w << 1; k++) {
                    ex[j][k] = M::pl(ex[j][k], M::inv_pl(M::cr(ex[i][k], ex[j][i])));
                }
            }
        }
        for (int i = h - 1; i > 0; i--) {
            for (int j = i - 1; j >= 0; j--) {
                for (int k = w; k < w << 1; k++) {
                    ex[j][k] = M::pl(ex[j][k], M::inv_pl(M::cr(ex[i][k], ex[j][i])));
                }
            }
        }
        std::vector<std::vector<T>> ret(h, std::vector<T>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                ret[i][j] = ex[i][w + j];
            }
        }
        return ret;
    }
    matrix pow(long long n) const {
        assert(h == w);
        matrix ret = identity(h), mul = *this;
        while (n > 0) {
            if (n & 1) { ret *= mul; }
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend std::ostream &operator<<(std::ostream &os, const matrix &rhs) {
        for (int i = 0; i < rhs.h; i++) {
            os << "[";
            for (int j = 0; j < rhs.w; j++) {
                os << rhs[i][j] << (j + 1 == rhs.w ? "]\n" : ",");
            }
        }
        return os;
    }
};

struct mint_mat {
    using T = mint;
    static T pl(const T &a, const T &b) { return a + b; }
    static T cr(const T &a, const T &b) { return a * b; }
    static T id_pl() { return 0; }
    static T id_cr() { return 1; }
    static T inv_pl(const T &a) { return -a; }
    static T inv_cr(const T &a) { return a.inv(); }
    static bool is_id_pl(const T &a) { return a == 0; };
};

int N, K;
int a[55][55];
signed main() {
    cin >> N >> K;
    matrix<mint_mat> mat(N, N);
    rep(i, N) {
        rep(j, N) {
            cin >> a[i][j];
            mat[i][j] = a[i][j];
        }
    }
    mat = mat.pow(K);
    mint ans = 0;
    rep(i, N) {
        rep(j, N) {
            ans += mat[i][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3760