#include<bits/stdc++.h>
using namespace std;


template<typename F>
struct Matrix {
  int rowNum, colNum;
  vector<vector<F>> cell;

  Matrix(int n) : rowNum(n), colNum(n) { // Identity matrix
    cell = vector<vector<F>>(n, vector<F>(n, 0));
    for (int i = 0; i < n; i++) cell[i][i] = F(1);
  }

  Matrix(int n, int m, int fill = 0) : rowNum(n), colNum(m) {
    cell.assign(n, vector<F>(m, fill));
  }

  Matrix(const Matrix &mat) : rowNum(mat.rowNum), colNum(mat.colNum) {
    cell = mat.cell;
  }

  vector<F>& operator[] (int i) { return cell[i]; }

  const vector<F>& operator[] (int i) const { return cell[i]; }

  Matrix& operator= (const Matrix &mat) {
    rowNum = mat.rowNum;
    colNum = mat.colNum;
    cell = mat.cell;
    return *this;
  }

  Matrix& operator*= (const Matrix &mat) {
    assert(colNum == mat.rowNum);
    Matrix res(rowNum, mat.colNum);
    for (int i = 0; i < rowNum; i++) {
      for (int j = 0; j < mat.colNum; j++) {
        for (int k = 0; k < colNum; k++) {
          res[i][j] = res[i][j] + cell[i][k] * mat[k][j];
        }
      }
    }
    return *this = res;
  }

  Matrix& operator^= (long long p) {
    assert(rowNum == colNum && p >= 0);
    Matrix res(rowNum);
    for (; p; p >>= 1) {
      if (p&1) res *= *this;
      *this *= *this;
    }
    return *this = res;
  }

  friend istream& operator>> (istream &is, Matrix &mat) {
    for (int i = 0; i < mat.rowNum; i++)
      for (int j = 0; j < mat.colNum; j++)
        is >> mat[i][j];
    return is;
  }

  friend ostream& operator<< (ostream &os, const Matrix &mat) {
    for (int i = 0; i < mat.rowNum; i++)
      for (int j = 0; j < mat.colNum; j++)
        os << mat[i][j] << " \n"[j == mat.colNum - 1];
    return os;
  }

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

  Matrix operator^ (const long long p) {
    Matrix res(*this);
    return (res ^= p);
  }
};

template <int mod>
struct ModInt {
  int val;
  int trim(int x) const { return x >= mod ? x - mod : x < 0 ? x + mod : x; }
  ModInt(int v = 0) : val(trim(v % mod)) {}
  ModInt(long long v) : val(trim(v % mod)) {}
  ModInt &operator=(int v) { return val = trim(v % mod), *this; }
  ModInt &operator=(const ModInt &oth) { return val = oth.val, *this; }
  ModInt operator+(const ModInt &oth) const { return trim(val + oth.val); }
  ModInt operator-(const ModInt &oth) const { return trim(val - oth.val); }
  ModInt operator*(const ModInt &oth) const { return 1LL * val * oth.val % mod; }
  ModInt operator/(const ModInt &oth) const {
    function<int(int, int, int, int)> modinv = [&](int a, int b, int x, int y) {
      if (b == 0) return trim(x);
      return modinv(b, a - a / b * b, y, x - a / b * y);
    };
    return *this * modinv(oth.val, mod, 1, 0);
  }
  bool operator==(const ModInt &oth) const { return val == oth.val; }
  ModInt operator-() const { return trim(mod - val); }
  template<typename T> ModInt pow(T pw) {
    bool sgn = false;
    if (pw < 0) pw = -pw, sgn = true;
    ModInt ans = 1;
    for (ModInt cur = val; pw; pw >>= 1, cur = cur * cur) {
      if (pw&1) ans = ans * cur;
    }
    return sgn ? ModInt{1} / ans : ans;
  }
};

using mint = ModInt<int(1e9 + 7)>;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  long long n, k; cin >> n >> k;
  Matrix<mint> M(n), arr(1, n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int a; cin >> a;
      M[i][j] = a;
    }
    arr[0][i] = 1;
  }
  arr *= M^k;
  cout << accumulate(arr[0].begin(), arr[0].end(), mint(0), [&](mint a, mint b) {
    return a + b;
  }).val << '\n';
}


Measured memory_bytes: 256