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

 

#define ll long long

#define X first

#define Y second

#define MP make_pair

 

using namespace std;



const int N = 123;

const ll mod = 1e9 + 7;             



int n;

struct mtx{

	ll a[N][N], len = n;

	mtx(){

		memset(a, 0, sizeof(a));

	}

	void operator *= (mtx b){

		int res[N][N];

		memset(res, 0, sizeof(res));

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

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

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

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

				}

			}

		}

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

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

				a[i][j] = res[i][j];

			}

		}

	}

};



mtx bin_pow(mtx x, ll y){

	mtx res;

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

			res.a[i][i] = 1;

	}

    

	while(y){

		if(y & 1LL)

			res *= x;

		

	/*	for(int i = 1;i <= n;i++){	

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

				cout << res.a[i][j] << " ";

	    	}

			cout << "\n";

		}

	*/	

		x *= x;

		y >>= 1LL;

	}

	return res;

}

   

int main () {

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	ll k;

	cin >> n >> k;

	mtx z;

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

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

			cin >> z.a[i][j];

	//z *= z;

	z = bin_pow(z, k);

	ll res = 0;

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

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

		//	cout << z.a[i][j] << " ";

			res += z.a[i][j], res %= mod;

	    }

		//cout << "\n";

	}

	cout << res;

}

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

 

#define int long long

//#pragma GCC optimize("Ofast")

//#pragma comment(linker, "/stack:200000000")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

 

 

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define forn(i, a, b) for(int i = (a); i <= (b); ++i)

#define all(x) x.begin(), x.end()

#define sz(s) (int)s.size()

#define pb push_back

#define ppb pop_back

#define s second

#define f first

 

 

using namespace std;

 

 

typedef pair < long long, long long > pll;    

typedef pair < int, int > pii;

typedef unsigned long long ull;         

typedef vector < pii > vpii;

typedef vector < int > vi;

typedef long double ldb;  

typedef long long ll;  

typedef double db;                      

 

 

const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;

const pii base = {1171, 3307}, Mod = {1e9 + 7, 1e9 + 9};

const db eps = 1e-12, pi = 3.14159265359;

const ll INF = 1e18;





void add (int &x, int y) {

	x += y;

	if (x >= mod)

		x -= mod;

	if (x < 0)

		x += mod;

}









vector < vi > mult (vector < vi > a, vector < vi > b) {

	int n = sz(a), m = sz(a[0]), k = sz(b[0]);

	vector < vi > res(n, vi(k));



	forn (i, 0, n - 1)                                                    	

		forn (j, 0, k - 1)

			forn (x, 0, m - 1)

				add(res[i][j], a[i][x] * 1ll * b[x][j] % mod);			 



	return res;

}



vector < vi > binpow (vector < vi > a, int n) {

	int m = sz(a);

	vector < vi > res(m, vi(m));	

	forn (i, 0, m - 1)

		res[i][i] = 1;



	while (n) {

		if (n & 1)

			res = mult(res, a);

		a = mult(a, a);

		n >>= 1;

	}



	return res;

}





int n, k;



main () {

	cin >> n >> k;

	vector < vi >  g(n, vi(n));

	forn (i, 0, n - 1)

		forn (j, 0, n - 1)

			cin >> g[i][j];



	g = binpow(g, k);	

	int ans = 0;;

	forn (i, 0, n - 1)

		forn (j, 0, n - 1)

			add(ans, g[i][j]);



	cout << ans << endl;

}