//https://codeforces.com/contest/1345/problem/A
//Author: BrownieTK

//#pragma GCC optimize("O3")

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

//========================Debug======================================

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifdef local
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

//========================TypeDefs===================================

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
typedef pair<int, lli> pil;

//=========================MACROS====================================

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define clz(n) __builtin_clz(n)
#define clzll(n) __builtin_clzll(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>

#define ofk order_of_key
#define fbo find_by_order
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set

//==============================FUNCTIONS===========================================

auto clk = clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void run_time()
{
#ifdef local
    cout << endl;
    cout << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return;
}

inline lli power(lli x, lli y, lli p = mod)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

inline lli modadd(lli a, lli b, lli m = mod)
{
    a += b;
    if (a >= m)
        a -= m;
    return a;
}

inline lli modmul(lli a, lli b, lli m = mod)
{
    return ((a % m) * (b % m)) % m;
}

inline lli modi(lli a, lli m = mod) { return power(a, m - 2, m); }

//================================CODE=============================================
struct matrix
{
    vector<vector<lli>> m;
};
void msi(matrix &m, lli a, lli b)
{
    m.m.resize(a);
    forz(i, a)
        m.m[i]
            .resize(b);
}
void minit(matrix &m, lli x)
{
    forz(i, m.m.size())
        forz(j, m.m[0].size())
            m.m[i][j] = x;
}
matrix mul(matrix m1, matrix m2)
{
    matrix m3;
    msi(m3, m1.m.size(), m2.m[0].size());
    forz(i, m3.m.size())
    {
        forz(j, m3.m[0].size())
        {
            m3.m[i][j] = 0;
            forz(k, m1.m[0].size())
                m3.m[i][j] = (m3.m[i][j] + m1.m[i][k] * m2.m[k][j]) % mod;
        }
    }
    return m3;
}
matrix mexp(matrix &mx, lli p)
{
    matrix res;
    msi(res, mx.m.size(), mx.m.size());
    minit(res, 0ll);
    forz(i, mx.m.size())
        res.m[i][i] = 1;
    while (p > 0)
    {
        if (p & 1)
            res = mul(res, mx);
        mx = mul(mx, mx);
        p = p >> 1;
    }
    return res;
}
int main()
{
    kira;
    lli n, m, k;
    cin >> n >> k;
    int u, v;
    matrix mat;
    msi(mat, n, n);
    minit(mat, 0ll);
    forz(i, n)
    {
        forz(j, n) cin >> mat.m[i][j];
    }
    mat = mexp(mat, k);
    lli ans = 0;
    forz(i, n)
    {
        forz(j, n)
        {
            ans = modadd(ans, mat.m[i][j]);
        }
    }
    p1(ans);
    return 0;
}

Measured memory_bytes: 384