// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;



	

struct Matrix{

  static const int maxn = 105;

  long long int A[maxn][maxn];

  int n;

 

  Matrix(int n_): n(n_) {

    for(int i = 0; i < n; ++i)

      for(int j = 0; j < n; ++j)

        A[i][j] = 0;

  }

 

  Matrix operator * (const Matrix& o) const {

    Matrix ret(n);

    for(int i = 0; i < n; ++i)

      for(int j = 0; j < n; ++j)

        for(int k = 0; k < n; ++k){

          long long int c = A[i][k] * o.A[k][j] % 1000000007;

          ret.A[i][j] = (ret.A[i][j] + c) % 1000000007;

        }

    return ret;

  }

 

  static Matrix identity(int n){

    Matrix ret(n);

    for(int i = 0; i < n; ++i)

      ret.A[i][i] = 1;

    return ret;

  }

 

  Matrix operator ^ (long long k) const {

    Matrix ret = identity(n);

    Matrix a = *this;

    while(k){

      if(k & 1)ret = ret * a;

      a = a * a;

      k /= 2;

    }

    return ret;

  }

 

};



int main(void) {

    long long int N, K;

    cin >> N >> K;

    Matrix matrix(N);

    for(int i=0; i<N; i++) {

        for(int j=0; j<N; j++) {

            cin >> matrix.A[i][j];

        }

    }

    // for(int k=0; k<K-1; k++) {

    //     Matrix matrix_tmp(N, vector<int>(N));

    //     for(int i=0; i<N; i++) {

    //         for(int j=0; j<N; j++) {

    //             for(int l=0; l<N; l++) {

    //                 matrix_tmp[i][j] += matrix[i][l] *matrix[l][j];

    //             }

    //         }

    //     }

    //     matrix = matrix_tmp;

    // }

    // for(int i=0; i<N; i++) {

    //     for(int j=0; j<N; j++) {

    //         cout << matrix[i][j] << " ";

    //     }

    //     cout << endl;

    // }

    matrix = matrix^(K);

    int ans = 0;

    for(int i=0; i<N; i++) {

        for(int j=0; j<N; j++) {

            ans = (ans + matrix.A[i][j]) % 1000000007;

        }

    }

    cout << ans << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7565627779542814x):
#include <bits/stdc++.h>

using namespace std;

const int mod =1000000007;



#define MODMATEXPO mod

typedef long long LL;

template<typename T, int N> 

struct matrix {

	T x[N + 1][N + 1];

	matrix(){memset(x, 0, sizeof(x));};

	matrix(T v) {

		memset(x, 0, sizeof(x));

		if(v!=0)

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

	}

	inline matrix operator*(const matrix &r) {

		matrix<T,N> p(0);

		for (int k = 1; k <= N; ++k) {

			for (int i = 1; i <= N; ++i) {

				if (x[i][k] == 0) continue;

				for (int j = 1; j <= N; ++j) {

					p.x[i][j] += x[i][k] * r.x[k][j];

					#ifdef MODMATEXPO

						p.x[i][j]%=MODMATEXPO;

					#endif

				}

			}

		}

		return p;

	}

	inline matrix mul(const matrix &r,const int col) {// col

		matrix<T,N> p(0);

		for (int k = 1; k <= N; ++k) {

			for (int i = 1; i <= N; ++i) {

				if (x[i][k] == 0) continue;

				for (int j = 1; j <= col; ++j) {

					p.x[i][j] += x[i][k] * r.x[k][j];

					#ifdef MODMATEXPO

						p.x[i][j]%=MODMATEXPO;

   					#endif

				}

			}

		}

		return p;

	}

	inline matrix pow(LL p) {

		matrix r(1), a = *this;

		for (; p > 0 ; p >>= 1) {

			if (p & 1) r = r * a;

			a = a * a;

		}

		return r;

	}

	T determinant() const {

		T r = 1, det[N + 1][N + 1];

		for (int i = 1; i <= N; ++i) memcpy(det[i], x[i], sizeof(x[i])); 

		for (int i = 1; i <= N; ++i) {

			for (int j = i + 1; j <= N; ++j) {

				while (det[j][i] != 0) {

					T ratio = det[i][i] / det[j][i];

					for (int k = i; k <= N; ++k) {

						det[i][k] -= ratio * det[j][k];

						swap(det[i][k], det[j][k]);

					}

					r = -r;

				}

			}

			r = r * det[i][i];

		}

		return r;

	}

	void print()

	{

		cout<<N<<endl;

		for (int i = 1; i <= N; i++)

		{

			for (int j = 1; j <= N; j++)cout << x[i][j] << ' '; cout << endl;

		}

	}

	void init(int *ara,int xx,int yy)//row,col

	{

		int k=0;

		for(int i=1;i<=xx;i++)

		{

			for(int j=1;j<=yy;j++)

			{

				x[i][j]=*(ara+k++);

			}

		}

	}

};





int main(int argc, char const *argv[])

{

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	matrix<long long,50> mat;

	int arr[50*50+10];

	int n;

	long long k;

	cin>>n>>k;

	for(int i=0;i<n*n;i++)cin>>arr[i];

	mat.init(arr,n,n);

	mat=mat.pow(k);

	int ans=0;

	for(int i=0;i<=n;i++){

		for(int j=0;j<=n;j++){

			ans+=mat.x[i][j];

			// cout<<mat.x[i][j]<<' ';

			if(ans>=mod)ans-=mod;

		}

		// cout<<endl;

	}

	cout<<ans<<endl;

	return 0;

}