#include <bits/stdc++.h>

using namespace std;

template <class T>
struct Matrix
{
	int row;
	int column;
	vector<vector<T>> v;
	vector<T> &operator[](int i) { return (v[i]); }
	Matrix(int i, int j)
	{
		init(i, j);
	}
	Matrix()
	{
		init(0, 0);
	}
	void init(int i, int j)
	{
		row = i;
		column = j;
		v.resize(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);
	}
	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);
	}
	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] = v[i][j] - b;
			}
		}
		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<T> accumu_sum()
	{
		Matrix<T> r(this->row+1, this->column+1);
		for (int i = 1; i <= this->row; i++)
		{
			for (int j = 1; j <= this->column; j++)
			{
				r[i][j] = this->v[i-1][j-1] + r[i-1][j] + r[i][j-1] - r[i-1][j-1];
			}
		}
		return (r);
	}
	T get_sum_accumu(int r1, int c1, int r2, int c2) //半開区間で指定
	{
		return v[r2][c2] + v[r1][c1] - v[r2][c1] - v[r1][c2];
	}

	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);
	}
	friend ostream &operator<<(ostream &lhs, const Matrix<T> &rhs)
	{
		for (int i = 0; i < rhs.row; i++)
		{
			for (int j = 0; j < rhs.column - 1; j++)
			{
				lhs << rhs.v[i][j] << " ";
			}
			lhs << rhs.v[i][rhs.column - 1];
			if (i != rhs.row-1) cout << endl;
		}
		return lhs;
	}
	friend istream &operator>>(istream &lhs, Matrix<T> &rhs)
	{
		for (int i = 0; i < rhs.row; i++)
		{
			for (int j = 0; j < rhs.column; j++)
			{
				lhs >> rhs.v[i][j];
			}
		}
		return lhs;
	}
};

template<int mod> struct ModInt {
	using ll = long long;
	int x;
	ModInt(ll a) {
		x = a % mod;
		if (x < 0) {
			x += mod;
		}
	}
	ModInt(int a) {
		x = a % mod;
		if (x < 0) {
			x += mod;
		}
	}
	ModInt() : x(0) {}
	inline ModInt& operator+=(const ModInt& rhs)
	{
		(*this) += rhs.x;
		return *this;
	}
	inline ModInt& operator+=(const int rhs)
	{
		x += rhs % mod;
		x %= mod;
		return *this;
	}
	inline ModInt& operator-=(const ModInt& rhs)
	{
		(*this) -= rhs.x;
		return *this;
	}
	inline ModInt& operator-=(const int rhs)
	{
		x += mod - rhs % mod;
		x %= mod;
		return *this;
	}
	inline ModInt& operator*=(const ModInt& rhs)
	{
		(*this) *= rhs.x;
		return *this;
	}
	inline ModInt& operator*=(const int rhs)
	{
		long long res = (long long) x * rhs;
		x = res % mod;
		return *this;
	}
	inline ModInt& operator/=(const ModInt& rhs)
	{
		(*this) /= rhs.x;
		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.x;
		return *this;
	}
	inline ModInt& operator=(const int rhs)
	{
		(*this).x = rhs % mod;
		return *this;
	}
	inline int operator==(const ModInt& rhs) const
	{
		return (*this) == rhs.x;
	}
	inline int operator==(const int rhs) const
	{
		return (*this).x == rhs % mod;
	}
	inline int operator!=(const ModInt& rhs) const
	{
		return (*this) != rhs.x;
	}
	inline int operator!=(const int rhs) const
	{
		return (*this).x != rhs % mod;
	}
	inline ModInt operator++(int unused)
	{
		ModInt res((*this).x);
		++(*this);
		return res;
	}
	inline ModInt& operator++()
	{
		(*this) += 1;
		return (*this);
	}
	inline ModInt operator--(int unused)
	{
		ModInt res((*this).x);
		--(*this);
		return res;
	}
	inline ModInt& operator--()
	{
		(*this) -= 1;
		return (*this);
	}
	inline ModInt operator+() const
	{
		return (*this);
	}
	inline ModInt operator-() const
	{
		(*this).x = mod - (*this).x
		(*this).x %= mod;
		return (*this);
	}
	int modpow(const int val, int p = mod - 2)
	{
		if (p == 0) return 1;
		if (p % 2) return (long long) val * modpow(val, p-1) % mod;
		long long t = modpow(val, p/2);
		int res = t * t % mod;
		return res;
	}
	operator int() const
	{
		return x;
	}
	friend ostream& operator<<(ostream& lhs, const ModInt& rhs)
	{
		lhs << rhs.x;
		return lhs;
	}
	friend istream& operator>>(istream& lhs, ModInt& rhs)
	{
		long long t;
		lhs >> t;
		rhs.x = t % mod;
		return lhs;
	}
	friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) += rhs;}
	friend const ModInt operator+(const ModInt& lhs, const int rhs)      {return ModInt(lhs) += rhs;}
	friend const ModInt operator+(int lhs, const ModInt& rhs)            {return ModInt(lhs) += rhs;}
	friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) -= rhs;}
	friend const ModInt operator-(const ModInt& lhs, const int rhs)      {return ModInt(lhs) -= rhs;}
	friend const ModInt operator-(int lhs, const ModInt& rhs)            {return ModInt(lhs) -= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) *= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const int rhs)      {return ModInt(lhs) *= rhs;}
	friend const ModInt operator*(int lhs, const ModInt& rhs)            {return ModInt(lhs) *= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) /= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const int rhs)      {return ModInt(lhs) /= rhs;}
	friend const ModInt operator/(int lhs, const ModInt& rhs)            {return ModInt(lhs) /= rhs;}
	friend const int    operator==(int lhs, const ModInt& rhs)           {return ModInt(lhs) == rhs;}
	friend const int    operator!=(int lhs, const ModInt& rhs)           {return ModInt(lhs) != rhs;}
};
using modint = ModInt<1000000007>;

using matrix = Matrix<modint>;

matrix modpow(matrix m, long long p)
{
	if (p == 0) {
		m.unit_matrix();
		return m;
	}
	if (p % 2) {
		return m * modpow(m, p-1);
	}
	matrix t = modpow(m, p/2);
	return t * t;
}

int main()
{
	int N;
	long long K;
	cin >> N >> K;
	matrix m(N, N);
	cin >> m;
	m = modpow(m, K);
	modint res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			res += m[i][j];
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 1664