#include <bits/stdc++.h>
#include <cstdio>

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
	sort(all(v)); \
	(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
	type x;          \
	cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f)                  \
	if ((f))                      \
	{                             \
		cout << (TRUE__) << endl; \
	}                             \
	else                          \
	{                             \
		cout << FALSE__ << endl;  \
	}
#define RS resize
#define CINV(v, N)             \
	do                         \
	{                          \
		v.RS(N);               \
		rep(i, N) cin >> v[i]; \
	} while (0);
#define RCINV(v, N)             \
	do                          \
	{                           \
		v.RS(N);                \
		rrep(i, N) cin >> v[i]; \
	} while (0);
template <typename T>
inline T GET()
{
	T val;
	cin >> val;
	return val;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

namespace mylib
{
using namespace std;
static const int mod = 1000000007;
struct ModInt
{
	int value;
	ModInt(int x) : value(x) {}
	ModInt(void) : value(0) {}
	inline ModInt &operator+=(const ModInt &rhs)
	{
		(*this) += rhs.value;
		return *this;
	}
	inline ModInt &operator+=(const int rhs)
	{
		value += rhs;
		value %= mod;
		return *this;
	}
	inline ModInt &operator-=(const ModInt &rhs)
	{
		(*this) -= rhs.value;
		return *this;
	}
	inline ModInt &operator-=(const int rhs)
	{
		value += mod - rhs;
		value %= mod;
		return *this;
	}
	inline ModInt &operator*=(const ModInt &rhs)
	{
		(*this) *= rhs.value;
		return *this;
	}
	inline ModInt &operator*=(const int rhs)
	{
		long long res = (long long)value * rhs;
		value = res % mod;
		return *this;
	}
	inline ModInt &operator/=(const ModInt &rhs)
	{
		(*this) /= rhs.value;
		return *this;
	}
	inline ModInt &operator/=(const int rhs)
	{
		long long res = modpow(rhs);
		(*this) *= res;
		return *this;
	}
	inline ModInt &operator=(const ModInt &rhs)
	{
		(*this) = rhs.value;
		return *this;
	}
	inline ModInt &operator=(const int &rhs)
	{
		(*this).value = rhs % mod;
		return *this;
	}
	inline int operator==(const ModInt &rhs) const
	{
		return (*this) == rhs.value;
	}
	inline int operator==(const int rhs) const
	{
		return (*this).value == rhs % mod;
	}
	inline int operator!=(const ModInt &rhs) const
	{
		return (*this) != rhs.value;
	}
	inline int operator!=(const int rhs) const
	{
		return (*this).value != rhs % mod;
	}
	int modpow(const int val, int p = mod - 2)
	{
		if (p == 0)
			return 1;
		long long res = 1;
		if (p % 2)
		{
			res = val;
		}
		long long t = modpow(val, p / 2);
		t = t * t % mod;
		res = res * t % mod;
		return (int)res;
	}
	operator int() const
	{
		return value;
	}
};
ostream &operator<<(ostream &lhs, const ModInt &rhs)
{
	lhs << rhs.value;
	return lhs;
}
istream &operator>>(istream &lhs, ModInt &rhs)
{
	long long t;
	lhs >> t;
	rhs.value = t % mod;
	return lhs;
}
const ModInt operator+(const ModInt &lhs, const ModInt &rhs) { return ModInt(lhs) += rhs; }
const ModInt operator+(const ModInt &lhs, const int rhs) { return ModInt(lhs) += rhs; }
const ModInt operator+(int lhs, const ModInt &rhs) { return ModInt(lhs) += rhs; }
const ModInt operator-(const ModInt &lhs, const ModInt &rhs) { return ModInt(lhs) -= rhs; }
const ModInt operator-(const ModInt &lhs, const int rhs) { return ModInt(lhs) -= rhs; }
const ModInt operator-(int lhs, const ModInt &rhs) { return ModInt(lhs) -= rhs; }
const ModInt operator*(const ModInt &lhs, const ModInt &rhs) { return ModInt(lhs) *= rhs; }
const ModInt operator*(const ModInt &lhs, const int rhs) { return ModInt(lhs) *= rhs; }
const ModInt operator*(int lhs, const ModInt &rhs) { return ModInt(lhs) *= rhs; }
const ModInt operator/(const ModInt &lhs, const ModInt &rhs) { return ModInt(lhs) /= rhs; }
const ModInt operator/(const ModInt &lhs, const int rhs) { return ModInt(lhs) /= rhs; }
const ModInt operator/(int lhs, const ModInt &rhs) { return ModInt(lhs) /= rhs; }
const int operator==(int lhs, const ModInt &rhs) { return ModInt(lhs) == rhs; }
const int operator!=(int lhs, const ModInt &rhs) { return ModInt(lhs) != rhs; }
} // namespace mylib

namespace mylib
{
template <typename T>
struct Matrix
{
	int row;	//行
	int column; //列
	vector<vector<T>> v;
	vector<T> &operator[](int i) { return (v[i]); }
	Matrix(int i, int j)
	{
		row = i;
		column = j;
		v.RS(i, vector<T>(j, 0));
	}
	Matrix(const Matrix &cp)
	{
		row = cp.row;
		column = cp.column;
		v = cp.v;
	}
	~Matrix()
	{
	}
	Matrix operator=(const Matrix &a)
	{
		row = a.row;
		column = a.column;
		v = a.v;
		return (*this);
	}

	Matrix operator+(const Matrix &a)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = v[i][j] + a.v[i][j];
			}
		}
		return (r);
	}

	Matrix operator-(const Matrix &a)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = v[i][j] - a.v[i][j];
			}
		}
		return (r);
	}
	Matrix operator*(const Matrix &a)
	{
		Matrix r(row, a.column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < a.column; j++)
			{
				for (int k = 0; k < column; k++)
				{
					r.v[i][j] += v[i][k] * a.v[k][j];
				}
			}
		}
		return (r);
	}
	Matrix operator*(const int b)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = b * v[i][j];
			}
		}
		return (r);
	}
	void unit_matrix()
	{
		int n = row;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				v[i][j] = 0;
				if (i == j)
					v[i][j] = 1;
			}
		}
	}

	Matrix transposed()
	{
		Matrix t(column, row);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				t[j][i] = v[i][j];
			}
		}
		return (t);
	}
};
template<typename T>
ostream &operator<<(ostream &lhs, const Matrix<T> &rhs)
{
	rep(i, rhs.row)
	{
		rep(j, rhs.column - 1)
		{
			lhs << rhs.v[i][j] << " ";
		}
		lhs << rhs.v[i][rhs.column - 1];
		if (i != rhs.row-1) cout << endl;
	}
	return lhs;
}
template<typename T>
istream &operator>>(istream &lhs, Matrix<T> &rhs)
{
	rep(i, rhs.row)
	{
		rep(j, rhs.column)
		{
			lhs >> rhs.v[i][j];
		}
	}
	return lhs;
}
}

void init()
{
}

using namespace mylib;

Matrix<ModInt> mypow(Matrix<ModInt> m, ll b) {
	if (b == 1) return m;
	if (b % 2) return m * mypow(m, b-1);
	m = mypow(m, b/2);
	return m * m;
}

void solve()
{
	int N;
	ll K;
	cin >> N >> K;
	Matrix<ModInt> a(N, N);
	cin >> a;
	a = mypow(a, K);
	ModInt res = 0;
	rep(i, N) rep(j, N) {
		res += a[i][j];
	}
	cout << res << endl;
}


Measured memory_bytes: 1664