#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


template<typename T, std::size_t S>
class vector_t {
public:
  T v_[S];

public:
  vector_t() {
    memset(v_, 0, sizeof(v_));

    v_[S - 1] = 1.0;
  };

  vector_t(const vector_t& v) {
    memcpy((void*)v.v_, (void*)v_, sizeof(v_));
  };

public:
  T& operator[](int i) {
    return v_[i];
  };

  T operator[](int i) const {
    return v_[i];
  };
};
  

template<typename T, std::size_t S>
class matrix_t {
public:
  T m_[S][S];

public:
  matrix_t() {
    for (int i = 0; i < S; i ++)
      for (int j = 0; j < S; j ++)
        m_[i][j] = i == j ? 1 : 0;
  };

  matrix_t(const matrix_t& m) {
    for (int i = 0; i < S; i ++)
      for (int j = 0; j < S; j ++)
        m_[i][j] = m[i][j];
  };

public:
  const T* operator[](int i) const {
    return m_[i];
  };

  T* operator[](int i) {
    return m_[i];
  };

public:
  matrix_t<T, S> operator*(const matrix_t<T, S>& m) const {
    matrix_t<T, S> mm;

    for (int i = 0; i < S; i ++)
      for (int j = 0; j < S; j ++) {
        T s = 0.0;

        for (int k = 0; k < S; k ++)
          (s += m_[i][k] * m[k][j] % MOD) %= MOD;

        mm[i][j] = s;
      }

    return mm;
  };

  matrix_t<T, S> operator^(long long n) const {
    matrix_t<T, S> m, mm(*this);

    for ( ; n; n >>= 1, mm *= mm)
      if (n & 1)
        m *= mm;

    return m;
  };

public:
  vector_t<T, S> operator*(const vector_t<T, S>& v) const {
    vector_t<T, S> vv;

    for (int i = 0; i < S; i ++) {
      vv[i] = 0;
      
      for (int j = 0; j < S; j ++)
        (vv[i] += m_[i][j] * v[j] % MOD) %= MOD;
    }

    return vv;
  };

public:
  matrix_t<T, S>& operator*=(const matrix_t<T, S>& m) {
    matrix_t<T, S> mm;

    for (int i = 0; i < S; i ++)
      for (int j = 0; j < S; j ++) {
        T s = 0.0;

        for (int k = 0; k < S; k ++)
          (s += m_[i][k] * m[k][j] % MOD) %= MOD;

        mm[i][j] = s;
      }

    memcpy((void*)m_, (void*)mm.m_, sizeof(m_));

    return *this;
  };

  matrix_t<T, S>& operator^=(long long n) {
    matrix_t<T, S> m, mm(*this);

    for ( ; n; n >>= 1, mm *= mm)
      if (n & 1)
        m *= mm;

    memcpy((void*)m_, (void*)m.m_, sizeof(m_));

    return *this;
  };

public:
  matrix_t<T, S> transposed() const {
    matrix_t<T, S> m;
    
    for (int i = 0; i < S; i ++)
      for (int j = 0; j < S; j ++)
        m[i][j] = m_[j][i];
    
    return m;
  };

public:
  matrix_t<T, S>& transpose() {
    for (int i = 0; i < S; i ++)
      for (int j = 0; j < S; j ++)
        std::swap(m_[i][j], m_[j][i]);
    
    return *this;
  };
};

template<typename T, std::size_t S>
class matrix_fn_t {
public:
  matrix_fn_t(matrix_t<T, S>& m) : m_(m) {};

public:
  matrix_t<T, S> pow(long long n) const {
    matrix_t<T, S> m, mm(m_);

    for ( ; n; n >>= 1, mm *= mm)
      if (n & 1)
        m *= mm;

    return m;
  };

private:
  matrix_t<T, S>& m_;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  long long K;

  std::cin >> N >> K;

  matrix_t<long long, 55> m;

  for (int i = 0; i < N; i ++)
    for (int j = 0; j < N; j ++)
      std::cin >> m[i][j];

  m.transpose();

  vector_t<long long, 55> v;

  for (int i = 0; i < N; i ++)
    v[i] = 1;

  v = (m ^ K) * v;

  long long x = 0;

  for (int i = 0; i < N; i ++)
    (x += v[i]) %= MOD;

  std::cout << x << std::endl;

  return 0;
}


Measured memory_bytes: 384