// 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: 2.6655879853973476x):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define _inf 0xcf

#define INF 0x3f3f3f3f

#define _INF 0xcfcfcfcf

#define pb push_back

#define debug1 cout << "&&";

#define debug2 cout << "**";

#define ms(a, x) memset(a, x, sizeof(a))

#define IO ios::sync_with_stdio(false), cin.tie(0);

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

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

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

mt19937_64 mrand(random_device{}());

const int mod = 1e9 + 7;

const int N = 50 + 10;

const int M = 1e6 + 10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) {

    ll ans = 1;

    for (; b; b >>= 1) {

        if (b & 1) ans = ans * a % mod;

        a = a * a % mod;

    }

    return ans;

}

inline ll Mul(ll a, ll b) {

    ll lf = a * (b >> 25ll) % mod * (1LL << 25) % mod;

    ll rg = a * (b & ((1ll << 25) - 1)) % mod;

    return (lf + rg) % mod;

}

inline ll C(ll y, ll x) {

    ll ans = 1;

    if (y < 0 || x < 0 || y < x) return 0;

    y %= mod;

    if (!y || !x) return 1;

    rep(i, 0, x - 1) ans = ans * (y - i) % mod;

    rep(i, 1, x) ans = ans * Pow(i, mod - 2) % mod;

    return ans;

}

/*====================================================*/



ll n, k, ans;



struct mat {

   ll a[N][N];

   mat() { ms(a, 0); }

   inline mat operator * (const mat &b) const {

      mat res;

      rep(i, 1, n) rep(k, 1, n) {

         ll tmp = a[i][k];

         rep(j, 1, n) {

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

         }

      }

      return res;

   }



   inline mat operator ^ (ll b) const {

      mat res, bas;

      rep(i, 1, n) res.a[i][i] = 1;

      rep(i, 1, n) rep(j, 1, n) bas.a[i][j] = a[i][j];

      for(; b; b >>= 1) {

         if(b & 1) res = res * bas;

         bas = bas * bas;

      }

      return res;

   }

}p;



int main() {

   IO

   cin >> n >> k;

   rep(i, 1, n) rep(j, 1, n) {

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

   }

   mat res = p^(k);

   rep(i, 1, n) rep(j, 1, n) {

      ans = (ans + res.a[i][j]) % mod;

   }

   cout << ans << endl;

   return 0;

}



/*



*/