#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
template <int MOD>
class ModInt {
  long long x;

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }
};
template <typename T>
class Matrix {
  vector<vector<T>> A;

 public:
  Matrix(size_t n, size_t m, T v = 0) : A(n, vector<T>(m, v)){};

  size_t height() const { return A.size(); }

  size_t width() const { return A[0].size(); }

  inline const vector<T> &operator[](int k) const { return A[k]; }
  inline vector<T> &operator[](int k) { return A[k]; }

  static Matrix I(size_t n) {
    Matrix m(n, n, 0);
    for (int i = 0; i < n; ++i) m[i][i] = 1;
    return m;
  }

  Matrix &operator+=(const Matrix &B) {
    size_t n = height(), m = width();
    assert(n == B.height() && m == B.width());
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        (*this)[i][j] += B[i][j];
      }
    }
    return (*this);
  }

  Matrix &operator-=(const Matrix &B) {
    size_t n = height(), m = width();
    assert(n == B.height() && m == B.width());
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        (*this)[i][j] -= B[i][j];
      }
    }
    return (*this);
  }

  Matrix &operator*=(const Matrix &B) {
    size_t n = height(), l = width(), m = B.width();
    assert(l == B.height());
    vector<vector<T>> C(n, vector<T>(m, 0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        for (int k = 0; k < l; ++k) {
          C[i][j] += (*this)[i][k] * B[k][j];
        }
      }
    }
    A.swap(C);
    return (*this);
  }

  Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }

  Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }

  Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }

  Matrix power(long long r) const {
    assert(height() == width());
    Matrix A(*this), B(Matrix::I(height()));
    while (r > 0) {
      if (r & 1) B *= A;
      A *= A;
      r >>= 1;
    }
    return B;
  }

  friend ostream &operator<<(ostream &os, const Matrix &A) {
    size_t n = A.height(), m = A.width();
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (j != 0) os << " ";
        os << A[i][j];
      }
      os << endl;
    }
    return os;
  }

  friend istream &operator>>(istream &is, Matrix &A) {
    size_t n = A.height(), m = A.width();
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        is >> A[i][j];
      }
    }
    return is;
  }
};

using mint = ModInt<1000000007>;

int N;
ll K;
vector<vector<int>> a;

int main() {
  cin >> N >> K;
  a.resize(N, vector<int>(N));

  Matrix<mint> R(N, N);
  cin >> R;
  R = R.power(K);

  mint ans = 0;
  rep(i, N) rep(j, N) ans += R[i][j];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384