// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long n,k,mod=1e9+7;

struct matrix{

	long long x[100][100];	

}mat;

matrix matrixidentity(long long sz)

{

	matrix res;

	for(int i=0;i<=sz;i++)

	{

		for(int j=0;j<=sz;j++)

		{

			res.x[i][j] = 0;

			if(i==j) res.x[i][j] = 1;

		}

	}

	return res;

}

matrix multiplication(matrix a,matrix b,int sz,long long md)

{

	matrix res;

	for(int i=0;i<sz;i++)

	{

		for(int j=0;j<sz;j++)

		{

			res.x[i][j] = 0;

			for(int k=0;k<sz;k++)

			{

				res.x[i][j]+=(a.x[i][k]%md*b.x[k][j]%md)%md;

				res.x[i][j]%=md;

			}

		}

	}

	return res;

}

matrix matpow(matrix a,long long p,long long md)

{

	matrix res;

	res = matrixidentity(n);

	while(p)

	{

		if(p%2) res = multiplication(res,a,n,md);

		

		a = multiplication(a,a,n,md);

		p/=2;

	}

	

	return res;

}

int main()

{

	scanf("%lld %lld",&n,&k);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<n;j++)

		{

			scanf("%lld",&mat.x[i][j]);

		}

	}

	mat = matpow(mat,k,mod);

	//mat = multiplication(mat,mat,n,mod);

	long long ans = 0;

//	printf("\n");

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<n;j++)

		{

			ans+=mat.x[i][j]%mod;

			ans%=mod;

			//printf("%lld ",mat.x[i][j]);

		}

		//printf("\n");

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.0029101009653787x):
#include <bits/stdc++.h>

using namespace std;

const int mod =1000000007;



#define MODMATEXPO mod

typedef long long LL;

template<typename T, int N> 

struct matrix {

	T x[N + 1][N + 1];

	matrix(){memset(x, 0, sizeof(x));};

	matrix(T v) {

		memset(x, 0, sizeof(x));

		if(v!=0)

		for (int i = 1; i <= N; ++i) x[i][i] = v;

	}

	inline matrix operator*(const matrix &r) {

		matrix<T,N> p(0);

		for (int k = 1; k <= N; ++k) {

			for (int i = 1; i <= N; ++i) {

				if (x[i][k] == 0) continue;

				for (int j = 1; j <= N; ++j) {

					p.x[i][j] += x[i][k] * r.x[k][j];

					#ifdef MODMATEXPO

						p.x[i][j]%=MODMATEXPO;

					#endif

				}

			}

		}

		return p;

	}

	inline matrix mul(const matrix &r,const int col) {// col

		matrix<T,N> p(0);

		for (int k = 1; k <= N; ++k) {

			for (int i = 1; i <= N; ++i) {

				if (x[i][k] == 0) continue;

				for (int j = 1; j <= col; ++j) {

					p.x[i][j] += x[i][k] * r.x[k][j];

					#ifdef MODMATEXPO

						p.x[i][j]%=MODMATEXPO;

   					#endif

				}

			}

		}

		return p;

	}

	inline matrix pow(LL p) {

		matrix r(1), a = *this;

		for (; p > 0 ; p >>= 1) {

			if (p & 1) r = r * a;

			a = a * a;

		}

		return r;

	}

	T determinant() const {

		T r = 1, det[N + 1][N + 1];

		for (int i = 1; i <= N; ++i) memcpy(det[i], x[i], sizeof(x[i])); 

		for (int i = 1; i <= N; ++i) {

			for (int j = i + 1; j <= N; ++j) {

				while (det[j][i] != 0) {

					T ratio = det[i][i] / det[j][i];

					for (int k = i; k <= N; ++k) {

						det[i][k] -= ratio * det[j][k];

						swap(det[i][k], det[j][k]);

					}

					r = -r;

				}

			}

			r = r * det[i][i];

		}

		return r;

	}

	void print()

	{

		cout<<N<<endl;

		for (int i = 1; i <= N; i++)

		{

			for (int j = 1; j <= N; j++)cout << x[i][j] << ' '; cout << endl;

		}

	}

	void init(int *ara,int xx,int yy)//row,col

	{

		int k=0;

		for(int i=1;i<=xx;i++)

		{

			for(int j=1;j<=yy;j++)

			{

				x[i][j]=*(ara+k++);

			}

		}

	}

};





int main(int argc, char const *argv[])

{

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	matrix<long long,50> mat;

	int arr[50*50+10];

	int n;

	long long k;

	cin>>n>>k;

	for(int i=0;i<n*n;i++)cin>>arr[i];

	mat.init(arr,n,n);

	mat=mat.pow(k);

	int ans=0;

	for(int i=0;i<=n;i++){

		for(int j=0;j<=n;j++){

			ans+=mat.x[i][j];

			// cout<<mat.x[i][j]<<' ';

			if(ans>=mod)ans-=mod;

		}

		// cout<<endl;

	}

	cout<<ans<<endl;

	return 0;

}