#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs ( llong n ) { return ( n < 0 ) ? -n : n; }
    boolean isMovable ( int x, int y, int w, int h ) { 
        return ( x >= 0 && y >= 0 && x < w && y < h ); }
}

#define int long long
int MOD = 1000000007;
struct Matrix {
    int size;
    llong data[64][64];

    Matrix operator* ( Matrix &b ) {
        Matrix res;
        res.size = size;
        memset(res.data, 0, sizeof(res.data));
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                for (int k = 0; k < size; k++) {
                    res.data[i][j] = (res.data[i][j]+ data[i][k] * b.data[k][j]) % MOD;
                }
            }
        }
        return res;
    }
    Matrix operator^( int n ) {
        Matrix res, x = *this;
        memset(res.data, 0, sizeof(res.data));
        res.size = x.size;
        for ( int i = 0; i < res.size; i++ ) {
            res.data[i][i] = 1;
        }
        while ( 0 < n ) {
            if ( n & 1 ) {
                res = ( res * x );
            }
            x = ( x * x );
            n >>= 1;
        }
        return res;
    }
};
namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {
        
        int n, k;
        read n >> k;
        Matrix mat;
        mat.size = n;
        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                read mat.data[i][j];
            }
        }

        mat = mat ^ k;
        int ans = 0;
        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                ans = ( ans + mat.data[i][j] ) % MOD;
            }
        }

        echo ans fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 384