// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long n,k,mod=1e9+7;

struct matrix{

	long long x[100][100];	

}mat;

matrix matrixidentity(long long sz)

{

	matrix res;

	for(int i=0;i<=sz;i++)

	{

		for(int j=0;j<=sz;j++)

		{

			res.x[i][j] = 0;

			if(i==j) res.x[i][j] = 1;

		}

	}

	return res;

}

matrix multiplication(matrix a,matrix b,int sz,long long md)

{

	matrix res;

	for(int i=0;i<sz;i++)

	{

		for(int j=0;j<sz;j++)

		{

			res.x[i][j] = 0;

			for(int k=0;k<sz;k++)

			{

				res.x[i][j]+=(a.x[i][k]%md*b.x[k][j]%md)%md;

				res.x[i][j]%=md;

			}

		}

	}

	return res;

}

matrix matpow(matrix a,long long p,long long md)

{

	matrix res;

	res = matrixidentity(n);

	while(p)

	{

		if(p%2) res = multiplication(res,a,n,md);

		

		a = multiplication(a,a,n,md);

		p/=2;

	}

	

	return res;

}

int main()

{

	scanf("%lld %lld",&n,&k);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<n;j++)

		{

			scanf("%lld",&mat.x[i][j]);

		}

	}

	mat = matpow(mat,k,mod);

	//mat = multiplication(mat,mat,n,mod);

	long long ans = 0;

//	printf("\n");

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<n;j++)

		{

			ans+=mat.x[i][j]%mod;

			ans%=mod;

			//printf("%lld ",mat.x[i][j]);

		}

		//printf("\n");

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.3752474467736575x):
#include <bits/stdc++.h>



using namespace std;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>





#define f first

#define s second

#define db long double

#define pb push_back

#define sz(c) (c).size()

#define all(c) (c).begin(),(c).end()



typedef long long ll;

typedef pair <int , int> ii;

typedef pair <ii , int> iii;

typedef vector <int> vi;

typedef vector <ii> vii;

typedef vector <iii> viii;

typedef vector <vi> vvi;

typedef vector <vii> vvii;



const ll mod = 1e9+7;

const int MAXN = 1e4+5;

const int MAXK = 1e2+5;

const db eps = 1e-13;



struct matriz {



    vvi m;

    int SZ;

    matriz( int Sz ) {

        vi v(Sz+1, 0);

        m = vvi( Sz+1, v );

        SZ = Sz;

    }

    matriz( int Sz , int V ) {

        vi v(Sz+1, 0);

        m = vvi( Sz+1, v );

        SZ = Sz;



        for( int i = 0 ; i <= SZ ; i++ )

            m[i][i] = V;

    }

    matriz operator * ( const matriz &X ) const {

        matriz res = matriz( SZ );

        for( int i = 1 ; i <= SZ ; i++ )

            for( int j = 1; j <= SZ ; j++ )

                for( int k = 1; k <= SZ ; k++ )

                    res.m[i][j] = ( res.m[i][j] + ( 1ll * m[i][k] * X.m[k][j] ) % mod ) % mod;

        return res;

    }



};





matriz expMatriz( matriz a , ll b ) {

    matriz res = matriz( a.SZ , 1 );

    while( b ) {



        if( b%2==1 ) {

            res = res*a;

        }

        a = a*a;

        b /= 2;



    }

    return res;

}



int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

    cout<<setprecision(11)<<fixed;



    int n;ll k;

    cin>>n>>k;

    matriz ans = matriz(n);

    for( int i = 1; i <= n ; i++ )

        for( int j = 1; j <= n ; j++ )

            cin>>ans.m[i][j];



    ans = expMatriz( ans , k );

    ll Ans = 0;

    for( int i = 1; i <= n ; i++ )

        for( int j = 1; j <= n ; j++ )

            Ans = ( Ans + ans.m[i][j] ) % mod;



    cout<<Ans<<"\n";



}