#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;
const int MOD = 1000000007;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = MOD;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) {}
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) {}
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

template<typename T>
class matrix {
private:
  int n;
  T *v;
public:
  matrix(int n, T x) : n(n) { v = new T[n*n]; REP(i, n) REP(j, n) v[i*n+j] = (i == j ? x : 0); }
  matrix(const matrix<T>& b) : n(b.n) { v = new T[n*n]; copy(b.v, b.v + n*n, v); }
  ~matrix() { delete [] v; }
  int size() const { return n; }
  void set(int r, int c, T x) { v[r*n+c] = x; }
  T get(int r, int c) const { return v[r*n+c]; }
  void swap(matrix<T>& b) { std::swap(n, b.n); std::swap(v, b.v); }
  matrix<T>& operator+=(const matrix<T>& b) { REP(p, n*n) v[p] += b.v[p]; return *this; }
  matrix<T>& operator-=(const matrix<T>& b) { REP(p, n*n) v[p] -= b.v[p]; return *this; }
  matrix<T>& operator*=(const matrix<T>& b) {
    matrix<T> r(n, 0);
    REP(i, n) REP(j, n){ T& t=r.v[i*n+j]; REP(k, n) t += v[i*n+k]*b.v[k*n+j]; }
    swap(r);
    return *this;
  }
};
template<typename T> matrix<T> operator+(matrix<T> a, const matrix<T>& b) { return a+=b; }
template<typename T> matrix<T> operator-(matrix<T> a, const matrix<T>& b) { return a-=b; }
template<typename T> matrix<T> operator*(matrix<T> a, const matrix<T>& b) { return a*=b; }
template<typename T> matrix<T> POW(matrix<T> a, long long n) {
  matrix<T> r(a.size(), 1);  for(; n; a*=a, n>>=1) if(n&1) r*=a; return r;
}
template<typename T> ostream& operator<<(ostream& os, const matrix<T>& a) {
  int n = a.size(); REP(i, n) REP(j, n) os << a.get(i, j) << (j == n-1 ? '\n' : ' '); return os;
}

int N;
ll K;
int g[55][55];

int main(void) {
  scanf("%d%lld", &N, &K);
  REP(i, N) REP(j, N) {
    scanf("%d", &g[i][j]);
  }
  matrix<mint> m(N, 0);
  REP(i, N) REP(j, N) {
    m.set(i, j, g[i][j]);
  }
  matrix<mint> mm = POW(m, K);
  mint res = 0;
  REP(i, N) REP(j, N) {
    res += mm.get(i, j);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256