/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

struct Mat {
   int sz;
   static const int mxn = 55, MOD = (int)1e9 + 7;
   int M[mxn][mxn];

   Mat(int n_) {
      sz = n_;
      reset();
   }

   static inline int add (int a, int b) {
      return (a + b)%MOD;
   }
   static inline int mul (int a, int b) {
      return int(1ll*a*b % MOD);
   }

   void reset() {
      for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j)
            M[i][j] = 0;
   }
   void make_I() {
      for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j)
         M[i][j] = (i == j ? 1 : 0);
   }

   Mat operator+(const Mat &other) {
      Mat sum(sz);
      for (int i = 0; i < sz; ++i)
         for (int j = 0; j < sz; ++j)
            sum.M[i][j] = add(M[i][j], other.M[i][j]);
      return sum;
   }

   Mat operator*(const Mat &other) {
      Mat prod(sz);
      for (int i = 0; i < sz; ++i) {
         for (int j = 0; j < sz; ++j) {
            prod.M[i][j] = 0;
            for (int k = 0; k < sz; ++k) {
               prod.M[i][j] = add(prod.M[i][j], mul(M[i][k], other.M[k][j]));
            }
         }
      }
      return prod;
   }

   Mat pow(ll k) {
      Mat M_cp(sz), ans(sz);
      for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j)
      {
         if (i == j) ans.M[i][j] = 1;
         M_cp.M[i][j] = M[i][j];
      }

      while (k) {
         if (k & 1) {
            ans = ans * M_cp;
         }
         M_cp = M_cp * M_cp;
         k >>= 1;
      }
      return ans;
   }
};


const int MOD = (int)1e9 + 7;
const int N = 55;
int n;
ll k;
int edge[N][N];
inline int add(int a, int b) {
   return (a + b) % MOD;
}

void solve() {
   Mat G(n);
   for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
         G.M[i][j] = edge[i][j];

   int total = 0;
   G = G.pow(k);
   for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
         total = add(total, G.M[i][j]);
   cout << total << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n >> k;
   for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
         cin >> edge[i][j];
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 384