#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&-x)
using namespace std;
const int N = 57, p = 1e9+7;
int n;
ll a[N][N];
void mul(ll a[N][N], ll b[N][N])
{
	ll c[N][N];
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			c[i][j] = 0;
			for(int k = 1; k <= n; k++)
			{
				c[i][j] = (c[i][j]+a[i][k]*b[k][j])%p;
			}
		}
	}
	memcpy(a, c, sizeof(c));
	return;
}
ll qpow(ll x[N][N], ll k)
{
	ll ret = 0, res[N][N] = {0};
	for(int i = 1; i <= n; i++)
	{
		res[i][i] = 1;
	}
	while(k)
	{
		if(k&1)
		{
			mul(res, x);
		}
		k >>= 1;
		mul(x, x);
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			ret = (ret+res[i][j])%p;
		}
	}
	return ret;
}
int main()
{
	ll k;
	scanf("%d%lld", &n, &k);
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	printf("%lld\n", qpow(a, k));
	return 0;
}