#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

template<class K>
struct Matrix{
    vector<vector<K>> dat;
    Matrix(size_t r,size_t c):dat(r,vector<K>(c,K())){}
    Matrix(size_t n):dat(n,vector<K>(n,K())){}
    Matrix(vector<vector<K>> dat):dat(dat){}
    size_t size() const{return dat.size();}
    vector<K> &operator[](int i){return dat[i];}
    const vector<K> &operator[](int i) const{return dat[i];}
    static Matrix I(size_t n){
        Matrix res(n);
        for (int i=0;i<n;++i) res[i][i]=K(1);
        return res;
    }
    Matrix &operator+=(const Matrix &B){
        for (int i=0;i<dat.size();++i)
            for (int j=0;j<dat[0].size();++j)
                (*this)[i][j]+=B[i][j];
        return (*this);
    }
    Matrix operator+(const Matrix &B) const{
        return Matrix(*this)+=B;
    }
    Matrix &operator-=(const Matrix &B){
        for (int i=0;i<dat.size();++i)
            for (int j=0;j<dat[0].size();++j)
                (*this)[i][j]-=B[i][j];
        return (*this);
    }
    Matrix operator-(const Matrix &B) const{
        return Matrix(*this)-=B;
    }
    Matrix &operator*=(const Matrix &B){
        vector<vector<K>> res(dat.size(),vector<K>(B[0].size(),K()));
        for (int i=0;i<dat.size();++i)
            for (int j=0;j<B[0].size();++j)
                for (int k=0;k<B.size();++k)
                    res[i][j]+=(*this)[i][k]*B[k][j];
        dat.swap(res);
        return (*this);
    }
    Matrix operator*(const Matrix &B) const{
        return Matrix(*this)*=B;
    }
    Matrix &operator^=(long long k){
        Matrix res=Matrix::I(size());
        while(k){
            if (k&1) res*=*this;
            *this*=*this; k>>=1;
        }
        dat.swap(res.dat);
        return (*this);
    }
    Matrix operator^(long long k) const{
        return Matrix(*this)^=k;
    }
};

template<uint_fast64_t Modulus> class modint{
    using u64=uint_fast64_t;
    public:
    u64 a;
    constexpr modint(const u64 x=0) noexcept:a(((x%Modulus)+Modulus)%Modulus){}
    constexpr u64 &value() noexcept{return a;}
    constexpr const u64 &value() const noexcept{return a;}
    constexpr modint &operator+=(const modint &rhs) noexcept{
        a+=rhs.a;
        if (a>=Modulus) a-=Modulus;
        return *this;
    }
    constexpr modint operator+(const modint &rhs) const noexcept{
        return modint(*this)+=rhs;
    }
    constexpr modint &operator++() noexcept{
        return ++a,*this;
    }
    constexpr modint operator++(int) noexcept{
        modint t=*this; return ++a,t;
    }
    constexpr modint &operator-=(const modint &rhs) noexcept{
        if (a<rhs.a) a+=Modulus;
        a-=rhs.a;
        return *this;
    }
    constexpr modint operator-(const modint &rhs) const noexcept{
        return modint(*this)-=rhs;
    }
    constexpr modint &operator--() noexcept{
        return --a,*this;
    }
    constexpr modint operator--(int) noexcept{
        modint t=*this; return --a,t;
    }
    constexpr modint &operator*=(const modint &rhs) noexcept{
        a=a*rhs.a%Modulus;
        return *this;
    }
    constexpr modint operator*(const modint &rhs) const noexcept{
        return modint(*this)*=rhs;
    }
    constexpr modint &operator/=(modint rhs) noexcept{
        u64 exp=Modulus-2;
        while(exp){
            if (exp&1) *this*=rhs;
            rhs*=rhs; exp>>=1;
        }
        return *this;
    }
    constexpr modint operator/(const modint &rhs) const noexcept{
        return modint(*this)/=rhs;
    }
    constexpr modint operator-() const noexcept{
        return modint(Modulus-a);
    }
    constexpr bool operator==(const modint &rhs) const noexcept{
        return a==rhs.a;
    }
    constexpr bool operator!=(const modint &rhs) const noexcept{
        return a!=rhs.a;
    }
    constexpr bool operator!() const noexcept{return !a;}
    friend constexpr modint pow(modint rhs,long long exp) noexcept{
        modint res{1};
        while(exp){
            if (exp&1) res*=rhs;
            rhs*=rhs; exp>>=1;
        }
        return res;
    }
    template<class T> friend constexpr modint operator+(T x,modint y) noexcept{
        return modint(x)+y;
    }
    template<class T> friend constexpr modint operator-(T x,modint y) noexcept{
        return modint(x)-y;
    }
    template<class T> friend constexpr modint operator*(T x,modint y) noexcept{
        return modint(x)*y;
    }
    template<class T> friend constexpr modint operator/(T x,modint y) noexcept{
        return modint(x)/y;
    }
    friend ostream &operator<<(ostream &s,const modint &rhs) noexcept {
        return s << rhs.a;
    }
    friend istream &operator>>(istream &s,modint &rhs) noexcept {
        u64 a; rhs=modint{(s >> a,a)}; return s;
    }
};

using mint=modint<MOD>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll K; cin >> N >> K;
    vector<vector<mint>> G(N,vector<mint>(N));
    rep(i,N) rep(j,N) cin >> G[i][j];
    Matrix<mint> M(G);
    M^=K;
    mint ans=0;
    rep(i,N) rep(j,N) ans+=M[i][j];
    cout << ans << endl;
}

Measured memory_bytes: 384