#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define int ll
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll; typedef cc_hash_table<int, int, hash<int>> intHashTable;
struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
inline int powMod(int a, int b) { int x = 1; while (b > 0) { if (b&1) x = (x*a) % MOD; a = (a*a) % MOD; b >>= 1; } return x; }
inline int multiply(int x, int y) { return ((x % MOD) * (y % MOD)) % MOD; }
inline int divide(int x, int y) { return ((x % MOD) * powMod(y % MOD, MOD-2)) % MOD; }
inline int ceil(int a, int b) { return (a+b-1)/b; }
int gcd (int a, int b) { while (b) { a %= b; swap(a, b); } return a; }
int lcm (int a, int b) { return a / gcd(a, b) * b; }
int inverseMod(int a, int m) { a = a % m; for (ll x = 1; x < m; x++) if ((a * x) % m == 1) return x; return -1; }
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
int str_replace(string& str, const string& from, const string& to, int limit = -1) { if(from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; }
template<int D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!");  template<typename... Args> vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) { } }; template<typename T> struct vec<1, T> : public vector<T> { vec(int n = 0, T val = T()) : vector<T>(n, val) { }};

template <typename T>
class Matrix
{
public:
    vector< vector<T> > mat;
    int rows, columns;
    Matrix() : rows(0), columns(0) {}
    Matrix(int _r, int _c) : rows(_r), columns(_c) { mat.assign(rows, vector<T>(columns)); }
    Matrix(int _r, int _c, const T &val) : rows(_r), columns(_c) { mat.assign(rows, vector<T>(columns, val)); }
    Matrix(int _n) : rows(_n), columns(_n)
    {
        mat.assign(_n, vector<T>(_n));
        for (int i = 0; i < _n; ++i) mat[i][i] = (T)1;
    }
    void display(int space = 5)
    {
        for (auto &x : mat)
        {
            for (auto &y : x) cout << setw(space) << y;
            cout << '\n';
        }
    }
    Matrix operator *(const Matrix<T> &B)
    {
        assert(columns == B.rows);
        Matrix<T> C(rows, B.columns, 0);
        for (int i = 0; i < rows; ++i)
        {
            for (int j = 0; j < B.columns; ++j)
            {
                for (int k = 0; k < columns; ++k)
                {
                    #ifdef MOD
                    C.mat[i][j] = (C.mat[i][j] + ((mat[i][k] * B.mat[k][j]) % MOD)) % MOD;
                    #else
                    C.mat[i][j] += mat[i][k] * B.mat[k][j];
                    #endif
                }
            }
        }
        return C;
    }
    Matrix operator *(T x)
    {
        Matrix<T> C(rows, columns);
        for (int i = 0; i < rows; ++i)
        {
            for (int j = 0; j < rows; ++j)
            {
                #ifdef MOD
                C.mat[i][j] = (mat[i][j] * x) % MOD;
                #else
                C.mat[i][j] = mat[i][j] * x;
                #endif
            }
        }
        return C;
    }
    Matrix operator +(const Matrix<T> &B)
    {
        assert(rows == B.rows); assert(columns == B.columns);
        Matrix <T> C(rows, columns, 0);
        for (int i = 0; i < rows; ++i)
        {
            for (int j = 0; j < columns; ++j)
            {
                #ifdef MOD
                C.mat[i][j] = (mat[i][j] + B.mat[i][j]) % MOD;
                #else
                C.mat[i][j] = mat[i][j] + B.mat[i][j];
                #endif
            }
        }
        return C;
    }
    Matrix operator -(const Matrix<T> &B)
    {
        assert(rows == B.rows); assert(columns == B.columns);
        Matrix <T> C(rows, columns, 0);
        for (int i = 0; i < rows; ++i)
        {
            for (int j = 0; j < columns; ++j)
            {
                #ifdef MOD
                C.mat[i][j] = (mat[i][j] - B.mat[i][j] + MOD) % MOD;
                #else
                C.mat[i][j] = mat[i][j] - B.mat[i][j];
                #endif
            }
        }
        return C;
    }
    Matrix operator^(ll n)
    {
        assert(rows == columns);
        Matrix<T> C(rows), X(rows, columns, 0);
        for (int i = 0; i < rows; ++i)
            for (int j = 0; j < columns; ++j)
                X.mat[i][j] = mat[i][j];
        while (n)
        {
            if (n&1) C *= X;
            X *= X;
            n /= 2;
        }
        return C;
    }
    Matrix transpose()
    {
        Matrix<T> res(columns, rows);
        for (int i = 0; i < columns; ++i)
            for (int j = 0; j < rows; ++j)
                res[i][j] = mat[j][i];
        return res;
    }
    void operator *=(const Matrix<T> &B) { auto res = operator*(B); rows = res.rows, columns = res.columns, mat = res.mat; }
    void operator *=(T x) { auto res = operator*(x); rows = res.rows, columns = res.columns, mat = res.mat; }
    void operator +=(const Matrix<T> &B) { auto res = operator+(B); rows = res.rows, columns = res.columns, mat = res.mat; }
    void operator -=(const Matrix<T> &B) { auto res = operator-(B); rows = res.rows, columns = res.columns, mat = res.mat; }
    void operator ^=(ll x) { auto res = operator^(x); rows = res.rows, columns = res.columns, mat = res.mat; }
    void transposeInplace() { auto res = transpose(); rows = res.rows, columns = res.columns, mat = res.mat; }
};

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k; cin >> n >> k;
    Matrix<int> g(n, n);
    for (auto &x : g.mat) for (auto &y : x) cin >> y;
    g ^= k;
    int res = 0;
    for (auto &x : g.mat) for (auto &y : x) res = (res + y) % MOD;
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 384