#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

template<typename T, int N, int M = N>
class Matrix {
	array<T, M> a[N];
	public:
	Matrix() {
		for (int i = 0; i < N; ++i)
			a[i].fill(T());
	}
	explicit Matrix(T x) {
		for (int i = 0; i < N; ++i)
			a[i].fill(0);
		for (int i = 0; i < N && i < M; ++i)
			a[i][i] = x;
	}
	Matrix(initializer_list<std::array<T, M>> x) {
		assert(x.size() <= N);
		for (int i = 0; i < x.size(); ++i)
			a[i] = *(x.begin() + i);
		for (int i = x.size(); i < N; ++i)
			a[i].fill(0);
	}
	void print() {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < M; ++j)
				cout << a[i][j] << " ";
			cout << "\n";
		}
	}
	array<T, M> &operator[](int x) {
		return a[x];
	}
	const array<T, M> &operator[](int x) const {
		return a[x];
	}
	Matrix operator+(const Matrix &x) {
		Matrix ans = *this;
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				ans[i][j] += x[i][j];
		return ans;
	}
	Matrix &operator+=(const Matrix &x) {
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				a[i][j] += x[i][j];
		return *this;
	}
	Matrix operator-(const Matrix &x) {
		Matrix ans = *this;
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				ans[i][j] -= x[i][j];
		return ans;
	}
	Matrix &operator-=(const Matrix &x) {
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				a[i][j] -= x[i][j];
		return *this;
	}
	template<int K>
	Matrix<T, N, K> operator*(const Matrix<T, M, K> &x) {
		Matrix<T, N, K> ans;
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j) {
				for (int k = 0; k < K; ++k) {
					ans[i][k] += a[i][j] * x[j][k];
				}
			}
		return ans;
	}
	Matrix operator*(T x) {
		Matrix ans = *this;
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				ans[i][j] *= x;
		return ans;
	}
	Matrix& operator*=(T x) {
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				a[i][j] *= x;
		return *this;
	}
};

template<ll MOD, int REV = 1>
class ModInt {
	public:
	static bool flag[REV];
	static ll rev[REV];
	static ll pw(ll a, ll b) {
		ll ans = 1; while (b) {
			while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
			ans = (ans * a) % MOD, --b;
		} return ans;
	}
	ll x;
	ModInt(): x(0) {}
	ModInt(ll x): x(x % MOD) {}
	ModInt operator+(ModInt b) {
		ModInt ans;
		ans.x = x + b.x;
		if (ans.x >= MOD)
			ans.x -= MOD;
		return ans;
	}
	ModInt &operator+=(ModInt b) {
		x += b.x;
		if (x >= MOD)
			x -= MOD;
		return *this;
	}
	ModInt operator-(ModInt b) {
		ModInt ans;
		ans.x = x - b.x;
		if (ans.x < 0)
			ans.x += MOD;
		return ans;
	}
	ModInt &operator-=(ModInt b) {
		x -= b.x;
		if (x < 0)
			x += MOD;
		return *this;
	}
	ModInt operator-() {
		ModInt ans;
		if (x == 0)
			return ans;
		ans.x = MOD - x;
		return ans;
	}
	ModInt operator*(ModInt b) {
		return ModInt(x * b.x);
	}
	ModInt &operator*=(ModInt b) {
		x = (x * b.x) % MOD;
		return *this;
	}
	ModInt inv() {
		if (MOD >= 2) {
			if (x >= REV)
				return ModInt(pw(x, MOD - 2));
			else {
				if (flag[x])
					return rev[x];
				else {
					flag[x] = 1;
					return rev[x] = pw(x, MOD - 2);
				}
			}
		}
		return ModInt();
	}
	ModInt operator/(ModInt b) {
		return ModInt(x * b.inv().x);
	}
	ModInt& operator/=(ModInt b) {
		x = (x * b.inv().x) % MOD;
		return *this;
	}
	bool operator==(ModInt b) {
		return x == b.x;
	}
	bool operator!=(ModInt b) {
		return x != b.x;
	}
};

template<ll MOD, int REV>
bool ModInt<MOD, REV>::flag[] = {};

template<ll MOD, int REV>
ll ModInt<MOD, REV>::rev[] = {};

const ll MOD = 1e9 + 7;

using matrix = Matrix<ModInt<MOD>, 60>;

matrix pw(matrix a, ll b) {
	matrix ans(1);
	while (b) {
		while (!(b & 1))
			b >>= 1, a = a * a;
		--b;
		ans = ans * a;
	}
	return ans;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	matrix a;
	int n;
	ll k;
	cin >> n >> k;
	Matrix<ModInt<MOD>, 60, 1> now;
	for (int i = 0; i < n; ++i)
		now[i][0] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			cin >> a[j][i].x;
	now = pw(a, k) * now;
	ModInt<MOD> ans = 0;
	for (int i = 0; i < n; ++i)
		ans += now[i][0];
	cout << ans.x << "\n";
	return 0;
}




Measured memory_bytes: 384