// Original C++ solution (slower):
//by Top1

#include <bits/stdc++.h>

     

#define f first

#define s second

#define ll long long

#define ld long double

#define ull unsigned long long

#define pii pair <int, int>

#define pll pair <long, long>

#define mp make_pair

#define pb push_back

#define pf push_front

#define pp pop_back

#define rev reverse

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

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

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

#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);

#define nxtp next_permutation

#define pvtp prev_permutation

#define KZ return 

#define x1 x21212121

#define y1 y21212121

#define sqr(x) x * x 

 

const int inf = (1e9) + 1;

const int mod = 1e9 + 7;

const int maxn = 4e5 + 111;

     

using namespace std;



ll n, q, k;



struct matrix{

	ll a[200][200];

	matrix() {}

	void read(){

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

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

				cin >> a[i][j];

	}

	void ans(){

		ll h = 0;

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

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

				h += a[i][j];

				h %= mod;

			}

		cout << h;

	}

	void write(){

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

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

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

			cout << endl;

		}

	}

	void ff(){

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

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

				a[i][j] = 0;

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

			a[i][i] = 1;

	}

	void operator *= (matrix &y){

		ll g[200][200];

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

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

				ll h = 0;

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

					h += a[i][q] * y.a[q][j];

					h %= mod;

				}

				g[i][j] = h;

			}

		}

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

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

				a[i][j] = g[i][j];

	}



};



matrix madpow(matrix x, ll b){

	matrix res;

	res.ff();

	while (b){

		if (b & 1)

			res *= x;

		x *= x;

		b >>= 1;

	}

	return res;

}



void solve(){                   

	cin >> n >> k;

	matrix x;

	x.read();

	matrix l = madpow(x, k);

	l.ans();

}



main(){

    boost;

	                 	

	q = 1;



	while (q--){

		solve();

	}

}


// Optimized solution to the same problem (faster):
//#pragma GCC target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

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

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

const int mod = (int)1e9 + 7;

const int N = (int)3e5 + 123;

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

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

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



int n;

ll k;



inline int add (int a, int b) {

   a += b;

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

   return a;

}



inline int mult (int a, int b) {

   return 1ll * a * b % mod;

}



struct Matrix {

   int a[55][55];

   Matrix () {

      memset (a, 0, sizeof a);

   }

   void one () {

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

         a[i][i] = 1;

   }

}a;



Matrix operator * (const Matrix &a, const Matrix &b) {

   Matrix c;

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

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

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

            c.a[i][j] = add (c.a[i][j], mult (a.a[i][k], b.a[k][j]));

   return c;

}



inline Matrix binpow (Matrix a, ll b) {

   Matrix res;

   res.one ();

   while (b) {

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

      a = a * a;

      b >>= 1;

   }

   return res;

}



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

   cin.tie (NULL), cout.tie (NULL);          

}                                                     



inline void Solve () {

   cin >> n >> k;

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

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

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

   a = binpow (a, k);

   int res = 0;

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

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

         res = add (res, a.a[i][j]);

   cout << res;                        

}



main () {                                       

// freopen (".in", "r", stdin);    

// freopen (".out", "w", stdout);              

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

}

                          

// Fastest known solution for this problem: