#include <bits/stdc++.h>
using namespace std;
int M = 1e9+7;
void mult(vector<vector<int>> &m1, vector<vector<int>> &m2){
    vector<vector<int>> res(m1.size(), vector<int> (m1.size()));
    for (int i=0; i<m1.size(); i++)
        for (int j=0; j<m1.size(); j++){
            for (int k=0; k<m1.size(); k++)
                res[i][j] = (res[i][j]+(1ll*m1[i][k]*m2[k][j])%M)%M;
        }
    m1 = res;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int N, ans=  0;
    long long K;
    cin >> N >> K;
    vector<vector<int>> m1(N, vector<int>(N)), m2 = m1;
    for (int i=0; i<N; i++)
        m1[i][i] = 1;
    for (auto &i: m2)
        for (auto &j: i)
            cin >> j;
    while (K){
        if (K&1)
            mult(m1, m2);
        K >>= 1;
        mult(m2, m2);
    }
    for (auto &i:m1)
        for (auto &j: i){
            ans += j;
            if (ans>=M)
                ans -= M;
        }
    cout << ans << "\n";
}