//         PAR_YUMMM            //
                                           //           CPP                //
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
ll const N=1e6+5;
ll const INF=9223372036854775807;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define len length()
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define uset unordered_set
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
 
#define forz(i, n) for (ll i = 0; i < n; i++)
#define fore(i, m, n) for (ll i = m; i <= n; i++)
#define rforz(i, n) for (ll i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (ll i = n; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define sexy ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 
#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

ll po(ll a,ll b,ll m){
    ll res=1;
    while(b>0){
        if(b&1){
            res=((res%m)*(a%m))%m;
        }
        a=((a%m)*(a%m))%m;
        b>>=1;
    }
    return res;
}

ll modi(ll a,ll m){
    return po(a,m-2,m);
}

ll lcm(ll a,ll b){ 
    return (a*b)/(gcd(a, b));
}

ll max(ll a,ll b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

ll min(ll a,ll b){
    if(a<b){
        return a;
    }else{
        return b;
    }
}

ll bins(ll ar[],ll l,ll r,ll x){ 
    if(r>=l){ 
        ll m=l+((r-l)/2); 
        if(ar[m]==x){
            return m; 
        }else if(ar[m]>x){ 
            return bins(ar,l,m-1,x);
        }else{
            return bins(ar,m+1,r,x); 
        }
    } 
    return -1; 
} 

ll nCr(ll n,ll k){ 
    ll C[n + 1][k + 1]; 
    ll i, j; 
    for(i=0;i<=n;i++){ 
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i){
                C[i][j]=1;  
            }else{
                C[i][j]=C[i-1][j-1]+C[i-1][j]; 
            }
        } 
    }
    return C[n][k]; 
} 

//vector<vector<ll>> adj(N); 
struct matrix{
    vector <vector<ll>> m;
};

void msi(matrix &m,ll a,ll b){
    m.m.resize(a);
    forz(i,a){
       m.m[i].resize(b);
    }
}

void minit(matrix &m,ll x){
    forz(i,m.m.size()){
        forz(j,m.m[0].size()){
            m.m[i][j]=x;
        }
    }
}

matrix mul(matrix m1,matrix m2){
    matrix m3;
    msi(m3,m1.m.size(),m2.m[0].size());
    forz(i,m3.m.size()){
        forz(j,m3.m[0].size()){
            m3.m[i][j]=0;
            forz(k,m1.m[0].size()){
                m3.m[i][j]=(m3.m[i][j]+((m1.m[i][k]*m2.m[k][j])%mod))%mod;
            }
        }
    }
    return m3;
}
matrix mexp(matrix &mx,ll p){
    matrix res;
    msi(res,mx.m.size(),mx.m.size());
    minit(res,0);
    forz(i,mx.m.size()){
        res.m[i][i]=1;
    }
    while(p>0){
        if(p&1){
            res=mul(res,mx); 
        }
        mx=mul(mx,mx);
        p=p>>1;
    }
    return res;
}

int main(){
    sexy;
    ll T,x,y,z,p,q,r;
    cin>>x>>y;
    matrix ans;
    msi(ans,x,x);
    forz(i,x){
        forz(j,x){
            cin>>ans.m[i][j];
        }
    }
    ans=mexp(ans,y);
    r=0;
    forz(i,x){
        forz(j,x){
            r=(r+(ans.m[i][j]))%mod;
        }
    }
    p1(r);
    return 0;
}

Measured memory_bytes: 512