/*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;
#ifndef CONVICTION
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#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...);
}

const int N = 55, MOD = (int)1e9 + 7;
inline int add (int a, int b)
{
   return (a + b) % MOD;
}
inline int mul (int a, int b) {
   return int(1ll*a*b % MOD);
}

struct Mat
{
   int sz;
   static const int mxn = 55;
   int M[mxn][mxn];

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

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

   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)  // O(n^2)
   {
      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) // O(n^3)
   {
      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) // O(n^3*logk)
   {
      Mat M_cp(*this), res(sz);
      res.make_I();

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

int n;
ll k;
int edge[N][N];

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];

   G = G.pow(k);

   int total = 0;
   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