/*

参考:
https://ei1333.github.io/luzhiled/snippets/math/matrix.html
verify:
https://atcoder.jp/contests/dp/tasks/dp_r
*/

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

using ll=long long int;

constexpr ll MOD=1e9+7;
//__builtin_popcount(S);
//#define int ll



template<typename T>
struct Matrix{
    vector<vector<T>> x;
    function<T(T,T)> plus;
    function<T(T,T)> mul;

    Matrix(){}
    Matrix(int h,int w):x(h,vector<T>(w)){}
    Matrix(int h,int w,const function<T(T,T)> &plus,const function<T(T,T)> &mul):x(h,vector<T>(w)),plus(plus),mul(mul){}
    Matrix(const vector<vector<T>> &x,const function<T(T,T)> &plus,const function<T(T,T)> &mul):x(x),plus(plus),mul(mul){}
    Matrix(const vector<vector<T>> &x):x(x){}

    inline int height()const{return (int)x.size();}

    inline int width()const{return (int)x[0].size();}

    inline vector<T> &operator[](int k){
        return x[k];
    }
    inline const vector<T> &operator[](int k)const{
        return x[k];
    }
    //O(hw)
    inline Matrix &operator+=(const Matrix &rhs)noexcept{
        int h=height(),w=width();
        assert(h==rhs.height() && w==rhs.width());
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++) x[i][j]=plus(x[i][j],rhs[i][j]);
        }
        return (*this);
    }
    //O(hw*rw) rhsに変更なし
    inline Matrix &operator*=(const Matrix &rhs)noexcept{
        x=((*this)*rhs).x;
        return (*this);
    }
    inline Matrix operator+(const Matrix &rhs)const noexcept{
        return Matrix(*this)+=rhs;
    }
    //O(hw*rw)
    inline Matrix operator*(const Matrix &rhs)const noexcept{
        int h=height(),w=width(),rw=rhs.width();
        assert(w==rhs.height());
        vector<vector<T>> res(h,vector<T>(rw,0));
        
        for(int i=0;i<h;i++){
            for(int j=0;j<rw;j++){
                for(int k=0;k<w;k++){
                    res[i][j]=plus(res[i][j],mul(x[i][k],rhs[k][j]));
                }
            }
        }
        return res;
    }
    //O(N^3logk)
    inline Matrix pow(ll k)const noexcept{
        assert(height()==width());
        Matrix res(height(),width(),plus,mul),t(x,plus,mul);
        bool flag=true;
        while(k>0){
            if(k&1){
                if(flag) res.x=t.x,flag=false;
                else res*=t;
            }
            t*=t;
            k>>=1;
        }
        return res;
    }
    //inline Matrix
    friend ostream &operator<<(ostream &os,const Matrix &m){
        int h=m.height(),w=m.width();
        os<<endl;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(j) os<<',';
                os<<m[i][j];
            }
            os<<endl;
        }
        return os;
    }


};

struct ModInt{
    using u64=uint_fast64_t;
    u64 a;
    constexpr ModInt() :a(0){}
    constexpr ModInt(ll x) :a((x>=0)?(x%MOD):(x%MOD+MOD) ) {}

    inline constexpr ModInt operator+(const ModInt rhs)const noexcept{
        return ModInt(*this)+=rhs;
    }
    inline constexpr ModInt operator-(const ModInt rhs)const noexcept{
        return ModInt(*this)-=rhs;
    }
    inline constexpr ModInt operator*(const ModInt rhs)const noexcept{
        return ModInt(*this)*=rhs;
    }
    inline constexpr ModInt operator/(const ModInt rhs)const noexcept{
        return ModInt(*this)/=rhs;
    }
    inline constexpr ModInt operator+(const ll rhs) const noexcept{
        return ModInt(*this)+=rhs;
    }
    inline constexpr ModInt operator-(const ll rhs)const noexcept{
        return ModInt(*this)-=rhs;
    }
    inline constexpr ModInt operator*(const ll rhs)const noexcept{
        return ModInt(*this)*=rhs;
    }
    inline constexpr ModInt operator/(const ll rhs)const noexcept{
        return ModInt(*this)/=rhs;
    }

    inline constexpr ModInt &operator+=(const ModInt rhs)noexcept{
        a+=rhs.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    inline constexpr ModInt &operator-=(const ModInt rhs)noexcept{
        if(rhs.a>a) a+=MOD;
        a-=rhs.a;
        return *this;
    }
    inline constexpr ModInt &operator*=(const ModInt rhs)noexcept{
        a=(a*rhs.a)%MOD;
        return *this;
    }
    inline constexpr ModInt &operator/=(ModInt rhs)noexcept{
        a=(a*rhs.inverse().a)%MOD;
        return *this;
    }
    inline constexpr ModInt &operator+=(const ll rhs)noexcept{
        a+=rhs;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    inline constexpr ModInt &operator-=(const ll rhs)noexcept{
        if(rhs>a) a+=MOD;
        a-=rhs;
        return *this;
    }
    inline constexpr ModInt &operator*=(const ll rhs)noexcept{
        a=(a*rhs)%MOD;
        return *this;
    }
    inline constexpr ModInt &operator/=(ll rhs)noexcept{
        a=(a*ModInt(rhs).inverse().a)%MOD;
        return *this;
    }

    inline constexpr ModInt operator=(ll x)noexcept{
        x%=MOD;
        if(x<0) x+=MOD;
        a=x;
        return *this;
    }

    inline constexpr bool operator==(const ModInt p)const noexcept{
        return a==p.a;
    }

    inline constexpr bool operator!=(const ModInt p)const noexcept{
        return a!=p.a;
    }

    inline constexpr ModInt pow(ll N) const noexcept{
        ModInt ans(1LL),p(a);
        while(N>0){
            if(N&1){
                ans*=p;
            }
            p*=p;
            N>>=1;
        }
        return ans;
    }
    inline constexpr ModInt inverse() const noexcept{
        return pow(MOD-2);
    }

};
inline constexpr ModInt operator+(const ll &a,const ModInt &b)noexcept{
    return ModInt(a)+=b;
}
inline constexpr ModInt operator-(const ll &a,const ModInt &b)noexcept{
    return ModInt(a)-=b;
}
inline constexpr ModInt operator*(const ll &a,const ModInt &b)noexcept{
    return ModInt(a)*=b;
}
inline constexpr ModInt operator/(const ll &a,const ModInt &b)noexcept{
    return ModInt(a)/=b;
}
//cout
inline ostream &operator<<(ostream &os,const ModInt &p) {
    return os<<p.a;
}

//cin
inline istream &operator>>(istream &is,ModInt &p) {
    ll t;
    is>>t;
    p=t;
    return is;
}



inline constexpr ModInt Mr(ll p){
    p%=MOD;
    if(p<0) p+=MOD;
    return ModInt(p);
}

struct Binominal{
    vector<ModInt> fac,finv,inv; //fac[n]:n! finv:(n!)の逆元
    int sz;
    Binominal(int n=10) :sz(1){
        if(n<=0) n=10;
        init(n);
    }
    inline void init(int n){
        fac.resize(n+1,1);
        finv.resize(n+1,1);
        inv.resize(n+1,1);
        for(int i=sz+1;i<=n;i++){
            fac[i]=fac[i-1]*i;
            inv[i]=MOD-inv[MOD%i]*(MOD/i);
            finv[i]=finv[i-1]*inv[i];
        }
        sz=n;
    }
    //nCk(n,k<=N) をO(1)で求める
    inline ModInt com(int n,int k){
        if(n<k) return ModInt(0);
        if(n<0 || k<0) return ModInt(0);
        if(n>sz) init(n);
        return fac[n]*finv[k]*finv[n-k];
    }
    //nCk(k<=N) をO(k)　で求める 
    inline ModInt rcom(ll n,int k){
        if(n<0 || k<0 || n<k) return ModInt(0);
        if(k>sz) init(k);
        ModInt ret(1);
        for(int i=0;i<k;i++){
            ret*=(n-i);
        }
        ret*=finv[k];
        return ret;
    }

    //重複組み合わせ n種類のものから重複を許してk個を選ぶ
    //〇がn個,|がk個
    inline ModInt h(int n,int k){
        return com(n+k-1,k);
    }
};



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout<<fixed<<setprecision(20);
    int N;
    ll K;
    cin>>N>>K;
    auto plus=[](ModInt a,ModInt b){
        return a+b;
    };

    auto mul=[](ModInt a,ModInt b){
        return a*b;
    };
    vector<vector<ModInt>> A(N,vector<ModInt>(N,0));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++) cin>>A[i][j];
    }
    Matrix<ModInt> M(A,plus,mul);
    auto ret=M.pow(K);
    ModInt sum=0;
    //cout<<ret;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++) sum+=ret[i][j];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 384