#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define mod 1000000007
#define DEBUG 1
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define range 200010
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#define endl '\n'
#endif

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
  cerr << *it << " = " << a <<" ";
  err(++it, args...);
}

const ll MAX_MAT = 51;

class matrix
{
    public:
    ll mat[MAX_MAT][MAX_MAT];
    int r,c;
 
    matrix(int r_assig = MAX_MAT, int c_assig = MAX_MAT)
    {
        r = r_assig, c = c_assig;
        forn(i,r)
            forn(j,c)
                mat[i][j] = 0;
    }
 
    inline matrix operator * (const matrix & a)
    {
        assert(c == a.r);
        matrix temp = matrix(r, a.c);
        forn(i, r)
            forn(j, a.c)
                forn(k, a.r)
                {
                    temp.mat[i][j] += (mat[i][k] * a.mat[k][j]) % mod;
                    if(temp.mat[i][j] >= mod) temp.mat[i][j] -= mod;
                }
    return temp;
    }
 
    inline matrix operator + (const matrix & a)
    {
        assert(c == a.c && r == a.r);
        matrix temp = matrix(r, c);
        forn(i, r)
            forn(j, c)
            {
                temp.mat[i][j] = mat[i][j] + a.mat[i][j];
                if(temp.mat[i][j] >= mod) temp.mat[i][j] -= mod;
            }
    return temp;
    }
 
    inline matrix operator - (const matrix & a)
    {
        assert(c == a.c && r == a.r);
        matrix temp = matrix(r, c);
        forn(i, r)
            forn(j, c)
            {
                temp.mat[i][j] = mat[i][j] - a.mat[i][j];
                if(temp.mat[i][j] < 0) temp.mat[i][j] += mod;
            }
    return temp;
    }
 
    inline void operator = (const matrix &a)
    {
        forn(i, a.r)
            forn(j, a.c)
                mat[i][j] = a.mat[i][j];
        r = a.r; c = a.c;
    }
};
 
matrix transpose(matrix a)
{
    matrix trans = matrix(a.c, a.r);
    forn(i, a.r)
        forn(j, a.c)
            trans.mat[j][i] = a.mat[i][j];
 
    return trans;
}
 
 
matrix matpow(matrix a, ll k)
{
    assert(a.r == a.c);
    matrix ans = matrix(a.r, a.c);
    forn(i, a.r)
        ans.mat[i][i] = 1;
    while(k)
    {
        if(k&1)
        ans = ans*a;
        a = a*a;
        k = k>>1;
    }
    return ans;
}
 





int main(){

 // freopen("test.txt","r",stdin);
  ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll n,k;
  cin>>n>>k;
  matrix X(n,n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)cin>>X.mat[i][j];
  }
  matrix a = matpow(X,k);
  ll ans=0;
  forn(i,n)forn(j,n)ans = (ans+a.mat[i][j])%MOD;
  cout<<ans<<endl;
  

  
  return 0;
}


Measured memory_bytes: 384