# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, a[220000], b[220000],dp[200000];
string str, ss;
bool f[220000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
template<class T>struct matrix {
	int n = 0, m = 0;
	vector<vector<T>>mat;
	matrix() {}
	matrix(int _n) {
		mat.resize(_n);
		for (int i = 0; i < _n; i++)
			mat[i].resize(_n);
		n = _n;
		m = _n;
	}
	matrix(int _n, int _m) {
		mat.resize(_n);
		for (int i = 0; i < _n; i++)
			mat[i].resize(_m);
		n = _n;
		m = _m;
	}
	int GetRank() {
		int h = mat.size(), w = mat[0].size();
		int res = 0, now = 0;
		for (int i = 0; i < h; i++) {
			T ma = 0.0;
			int pivot;
			for (int j = i; j < h; j++) {
				if (mat[j][now] > ma) {
					ma = mat[j][now];
					pivot = j;
				}
			}
			if (ma == 0.0) {
				now++;
				if (now == w) break;
				i--;
				continue;
			}
			if (pivot != i) {
				for (int j = 0; j < w; j++) {
					swap(mat[i][j], mat[pivot][j]);
				}
			}
			T tmp = 1.0 / mat[i][now];
			for (int j = 0; j < w; j++) mat[i][j] *= tmp;
			for (int j = 0; j < h; j++) {
				if (i != j) {
					T tmp2 = mat[j][now];
					for (int k = 0; k < w; k++) {
						mat[j][k] -= mat[i][k] * tmp2;
					}
				}
			}
			res++;
		}
		return res;
	}
	bool Inv(matrix<T> &inv) {
		assert(mat.size() == mat[0].size() && inv.n == inv.m);
		int n = mat.size();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				inv.mat[i][j] = (i == j ? 1.0 : 0.0);
			}
		}
		for (int i = 0; i < n; i++) {
			T ma = 0.0;
			int pivot;
			for (int j = i; j < n; j++) {
				if (mat[j][i] > ma) {
					ma = mat[j][i];
					pivot = j;
				}
			}
			if (ma == 0.0) return false;
			if (pivot != i) {
				for (int j = 0; j < n; j++) {
					swap(mat[i][j], mat[pivot][j]);
					swap(inv.mat[i][j], inv.mat[pivot][j]);
				}

			}
			T tmp = 1.0 / mat[i][i];
			for (int j = 0; j < n; j++) {
				mat[i][j] *= tmp;
				inv.mat[i][j] *= tmp;
			}
			for (int j = 0; j < n; j++) {
				if (i != j) {
					T tmp2 = mat[j][i];
					for (int k = 0; k < n; k++) {
						mat[j][k] -= mat[i][k] * tmp2;
						inv.mat[j][k] -= inv.mat[i][k] * tmp2;
					}
				}
			}
		}
		return true;
	}
	matrix<T> operator+(const matrix<T> &b) {
		assert(mat.size() == b.n && mat[0].size() == b.m);
		int h = mat.size(), w = mat[0].size();
		matrix<T> c(h, w);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				c.mat[i][j] = mat[i][j] + b.mat[i][j];
			}
		}
		return c;
	}
	matrix<T> operator-(const matrix<T> &b) {
		assert(mat.size() == b.n&& mat[0].size() == b.m);
		int h = mat.size(), w = mat[0].size();
		matrix<T> c(h, w);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				c.mat[i][j] = mat[i][j] - b.mat[i][j];
			}
		}
		return c;
	}
	matrix<T> operator*(const matrix<T> b) {
		assert(mat[0].size() == b.n);
		matrix<T> c(mat.size(), b.m);
		for (int i = 0; i < mat.size(); i++) {
			for (int k = 0; k < b.n; k++) {
				for (int j = 0; j < b.m; j++) {
					c.mat[i][j] = (c.mat[i][j] + mat[i][k] * b.mat[k][j])%MOD;
				}
			}
		}
		return c;
	}
	matrix<T> operator*(T b) {
		matrix<T> c(mat.size(), mat[0].size());
		for (int i = 0; i < mat.size(); i++) {
			for (int j = 0; j < mat[0].size(); j++) {
				c.mat[i][j] = mat[i][j] * b;
			}
		}
		return c;
	}
	matrix<T> operator%(LL b) {
		matrix<T> c(mat.size(), mat[0].size());
		for (int i = 0; i < mat.size(); i++) {
			for (int j = 0; j < mat[0].size(); j++) {
				c.mat[i][j] = mat[i][j] % b;
			}
		}
		return c;
	}

	matrix<T> Pow(long long n) {
		assert(mat.size() == mat[0].size());
		matrix<T> b(mat.size()), c(mat.size());
		c = *this;
		for (int i = 0; i < mat.size(); i++) {
			b.mat[i][i] = 1;
		}
		while (n > 0) {
			if (n & 1) {
				b = b * c;
				b = b % MOD;
			}
			c = c * c;
			c = c % MOD;
			n >>= 1;
		}
		return b;
	}
	T det() {
		T det = 1.0, buf;
		//三角行列を作成
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				if (i<j) {
					buf = mat[j][i] / mat[i][i];
					for (int k = 0; k<n; k++) {
						mat[j][k] -= mat[i][k] * buf;
					}
				}
			}
		}

		//対角部分の積
		for (int i = 0; i<n; i++) {
			det *= mat[i][i];
		}
		return det;
	}
	matrix<T> rev() {
		matrix<T> inv_a(n, m), cp(n, m);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++) {
				inv_a.mat[i][j] = mat[i][j];
				cp.mat[i][j] = mat[i][j];
			}
		T buf;
		//単位行列を作る
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				inv_a.mat[i][j] = (i == j) ? 1.0 : 0.0;
			}
		}
		//掃き出し法
		for (int i = 0; i<n; i++) {
			buf = 1 / cp.mat[i][i];
			for (int j = 0; j<n; j++) {
				cp.mat[i][j] *= buf;
				inv_a.mat[i][j] *= buf;
			}
			for (int j = 0; j<n; j++) {
				if (i != j) {
					buf = cp.mat[j][i];
					for (int k = 0; k<n; k++) {
						cp.mat[j][k] -= cp.mat[i][k] * buf;
						inv_a.mat[j][k] -= inv_a.mat[i][k] * buf;
					}
				}
			}
		}
		return inv_a;
	}
	void PrintMatrix() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << mat[i][j] << ' ';
			}
			cout << endl;
		}
	}
};
int main() {
	cin >> n >> m;
	matrix<LL> mat(n);
	rep(i, n) {
		rep(j, n) {
			LL x;
			cin >> x;
			mat.mat[i][j] = x;
		}
	}
	matrix<LL> ret=mat.Pow(m);
	rep(i, n)rep(j, n) { ans += ret.mat[i][j]; ans %= MOD; }
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560