#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename R>
struct Matrix {
	vector<vector<R>> a;
	Matrix() {}
	Matrix(int n, int m) :a(n, vector<R>(m)) {}
	int h()const { return a.size(); }
	int w()const { return a[0].size(); }
	vector<R> &operator[](size_t i) { return a[i]; }
	const vector<R> &operator[](size_t i)const { return a[i]; }
	Matrix &operator*=(const Matrix &b) {
		assert(w() == b.h());
		int n = h(), m = w(), r = b.w();
		Matrix c(n, r);
		for (int i = 0; i < n; i++)for (int j = 0; j < r; j++)for (int k = 0; k < m; k++)
			c[i][j] += a[i][k] * b[k][j];
		return *this = c;
	}
	static Matrix I(int n) {
		Matrix m(n, n);
		for (int i = 0; i < n; i++)m[i][i] = 1;
		return m;
	}
};

template<typename R>
Matrix<R> pow(Matrix<R> a, unsigned long long k) {
	Matrix<R> r = Matrix<R>::I(a.h());
	while (k) {
		if (k & 1)r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}

template<int MOD>
struct ModInt {
	static const int kMod = MOD;
	unsigned x;
	ModInt() :x(0) {}
	ModInt(signed x_) { x_ %= MOD; if (x_ < 0)x_ += MOD; x = x_; }
	ModInt(signed long long x_) { x_ %= MOD; if (x_ < 0)x_ += MOD; x = x_; }
	int get()const { return (int)x; }
	ModInt &operator+=(ModInt m) { if ((x += m.x) >= MOD)x -= MOD; return *this; }
	ModInt &operator-=(ModInt m) { if ((x += MOD - m.x) >= MOD)x -= MOD; return *this; }
	ModInt &operator*=(ModInt m) { x = (unsigned long long)x*m.x%MOD; return *this; }
	ModInt &operator/=(ModInt m) { return *this *= m.inverse(); }
	ModInt operator+(ModInt m)const { return ModInt(*this) += m; }
	ModInt operator-(ModInt m)const { return ModInt(*this) -= m; }
	ModInt operator*(ModInt m)const { return ModInt(*this) *= m; }
	ModInt operator/(ModInt m)const { return ModInt(*this) /= m; }
	ModInt operator-()const { return ModInt(MOD - (signed)x); }
	bool operator==(ModInt m)const { return x == m.x; }
	bool operator!=(ModInt m)const { return x != m.x; }
	ModInt inverse()const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		if (u < 0)u += MOD;
		return ModInt(u);
	}
};
template<int MOD>
ostream &operator<<(ostream &os, const ModInt<MOD> &m) { return os << m.x; }
template<int MOD>
istream &operator>>(istream &is, ModInt<MOD> &m) { signed long long s; is >> s; m = ModInt<MOD>(s); return is; };

template<int MOD>
ModInt<MOD> pow(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while (k) {
		if (k & 1)r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}

using mint = ModInt<MOD>;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long N, K; cin >> N >> K;
	Matrix<mint> a(N, N);
	rep(i, 0, N)rep(j, 0, N)
		cin >> a[i][j];
	auto res = pow(a, K);
	mint ans = 0;
	rep(i, 0, N)rep(j, 0, N)
		ans += res[i][j];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256