#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)
#define SP(i)           fixed << setprecision(i) 

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741
struct Matrix {
  	static const long long MOD = 1e9 + 7;
  	static const long long SQMOD = (long long) MOD * MOD;
  	static long long const N = 105;
  	using T = long long;
  	T x[N][N];
  	long long n, m;
  	Matrix(long long _n = N, long long _m = N, T val = 0): n(_n), m(_m) {
    	for (long long i = 0; i < n; ++i) for (long long j = 0; j < m; ++j)
      	x[i][j] = val;
  	}
  	Matrix(const vector<vector<long long>> &&mat) {
    	n = (long long) mat.size();
    	m = (long long) mat[0].size();
    	for (long long i = 0; i < n; ++i) for (long long j = 0; j < m; ++j)
      	x[i][j] = mat[i][j];
  	}
  	Matrix& operator = (const vector<vector<long long>> &&mat) {
    	return *this = Matrix(forward<decltype(mat)>(mat));
  	}
  	T* operator [] (long long r) {
    	return x[r];
  	}
  	const T* operator [] (long long r) const {
    	return x[r];
  	}
  	static Matrix unit(long long n) {
    	Matrix res(n, n);
    	for (long long i = 0; i < n; i++) res[i][i] = 1;
    	return res;
  	}
  	Matrix& operator += (const Matrix &rhs) {
    	assert (n == rhs.n && m == rhs.m);
    	for (long long i = 0; i < n; ++i) for (long long j = 0; j < m; ++j) {
    	  	x[i][j] += rhs[i][j];
      		if (x[i][j] >= MOD) x[i][j] -= MOD;
    	}
    	return *this;
  	}
  	Matrix operator + (const Matrix &rhs) const {
    	Matrix lhs(*this);
    	return lhs += rhs;
  	}
  	friend Matrix operator * (const Matrix &A, const Matrix &B) {
    	assert (A.m == B.n);
    	Matrix res(A.n, B.m);
    	for (long long i = 0; i < res.n; i++) for (long long j = 0; j < res.m; j++) {
      		long long sum = 0LL;
      		for (long long k = 0; k < A.m; k++) {
        		sum += (long long) A[i][k] * B[k][j];
        		if (sum >= SQMOD) sum -= SQMOD;
      		}
      		res[i][j] = (long long) (sum % MOD);
    	}
    	return res;
  	}
  	friend Matrix operator ^ (Matrix base, long long ex) {
    	assert (base.n == base.m);
    	Matrix res = Matrix::unit(base.n);
    	while (ex > 0) {
      		if (ex & 1) res = res * base;
      		base = base * base;
      		ex >>= 1;
    	}
    	return res;
  	}
  	Matrix& operator *= (const Matrix &rhs) {
    	return *this = *this * rhs;
  	}
  	Matrix& operator ^= (const long long &ex) {
    	return *this = *this ^ ex;
  	}
  	friend ostream &operator << (ostream &os, const Matrix& A) {
    	os << "(" << A.n << " x " << A.m << ")" << endl;
    	os << string(A.m * 2, '-');
    	for (long long i = 0; i < A.n; ++i) {
      		os << endl;
      		for (long long j = 0; j < A.m; ++j) os << A[i][j] << ' ';
    	}
    	return os << endl << string(A.m * 2, '-');
  	}
};
void solve() {
    ll n,k;
    cin>>n>>k;
    Matrix m(n,n);
    rep(i,0,n){
    	rep(j,0,n){
    		ll a;
    		cin>>a;
    		m[i][j]=a;
    	}
    }
    m ^= (k);
    ll meow=0;
    rep(i,0,n){
    	rep(j,0,n){
    		meow=(meow%hell+m[i][j]%hell)%hell;
    	}
    }
    cout<<meow<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 640