#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

template<int64_t mod>
struct ModInt {
    int64_t value;

    ModInt() : value(0) {}
    ModInt(int64_t x) : value(x >= 0 ? x % mod : (mod - ((-x) % mod) % mod)) {}

    ModInt &operator+=(const ModInt &input) {
        value += input.value;
        if (value >= mod) value -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &input) {
        value += (mod - input.value);
        if (value >= mod) value -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &input) {
        value = value * input.value % mod;
        return *this;
    }

    ModInt &operator/=(const ModInt &input) {
        *this *= input.inverse();
        return *this;
    }

    ModInt inverse() const {
        int64_t base = value, p = mod;
        pair<int64_t, int64_t> save = {1, 0};
        while (p) {
            int64_t temp = base / p;
            swap(base -= temp * p, p);
            swap(save.first -= temp * save.second, save.second);
        }
        return ModInt(save.first);
    }

    ModInt operator-() const { return ModInt(-value); }

    ModInt operator-(const ModInt &input) const { return ModInt(*this) -= input; }

    ModInt operator+(const ModInt &input) const { return ModInt(*this) += input; }

    ModInt operator*(const ModInt &input) const { return ModInt(*this) *= input; }

    ModInt operator/(const ModInt &input) const { return ModInt(*this) /= input; }

    bool operator==(const ModInt &comparsion) const { return value == comparsion.value; }

    bool operator!=(const ModInt &comparsion) const { return value != comparsion.value; }

    friend istream &operator>>(istream &stream, ModInt &input) {
        int64_t temp;
        stream >> temp;
        input = ModInt<mod>(temp);
        return stream;
    }

    friend ostream &operator<<(ostream &stream, const ModInt &input) {
        return stream << input.value;
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), x(value);
        while (n > 0) {
            if (n and 1) ret *= x;
            x *= x;
            n >>= 1;
        }
        return ret;
    }

    static const int64_t get_mod() { return mod; }
};

using modint = ModInt<MOD>;

template<typename T>
class Matrix {
private:
    vector<vector<T>> data;
    const size_t height, width;

public:
    Matrix(size_t height, size_t width) : height(height), width(width), data(height, vector<T>(width, 0)) {}

    Matrix(size_t N) : height(N), width(N), data(N, vector<T>(N, 0)) {}

    Matrix(Matrix const &copy_matrix) : height(copy_matrix.height), width(copy_matrix.width), data(copy_matrix.data) {}

    static Matrix generate_identity_matrix(size_t N) {
        Matrix ret(N);
        for (size_t index = 0; index < N; index++) ret.data[index][index] = 1;
        return ret;
    }

    Matrix &operator+=(const Matrix &operation_matrix) {
        assert(height == operation_matrix.height && width == operation_matrix.width);
        for (size_t height_index = 0; height_index < height; height_index++) {
            for (size_t width_index = 0; width_index < width; width_index++) {
                data[height_index][width_index] += operation_matrix.data[height_index][width_index];
            }
        }
        return *this;
    }

    Matrix &operator-=(const Matrix &operation_matrix) {
        assert(height == operation_matrix.height && width == operation_matrix.width);
        for (size_t height_index = 0; height_index < height; height_index++) {
            for (size_t width_index = 0; width_index < width; width_index++) {
                data[height_index][width_index] -= operation_matrix.data[height_index][width_index];
            }
        }
        return *this;
    }

    Matrix &operator*=(const Matrix &operation_matrix) {
        assert(width == operation_matrix.height);
        Matrix ret(height, operation_matrix.width);
        for (size_t height_index = 0; height_index < height; height_index++) {
            for (size_t width_index = 0; width_index < operation_matrix.width; width_index++) {
                for (size_t target_index = 0; target_index < width; target_index++) {
                    ret.data[height_index][width_index] += data[height_index][target_index] * operation_matrix.data[target_index][width_index];
                }
            }
        }
        data.swap(ret.data);
        return *this;
    }

    Matrix &operator^=(uint64_t operation_pow) {
        Matrix ret = generate_identity_matrix(height);
        while (operation_pow > 0) {
            if (operation_pow & 1) ret *= *this;
            *this *= *this;
            operation_pow >>= 1;
        }
        data.swap(ret.data);
        return *this;
    }

    Matrix &operator+(const Matrix &operation_matrix) const {
        return Matrix(*this) += operation_matrix;
    }

    Matrix &operator-(const Matrix &operation_matrix) const {
        return Matrix(*this) -= operation_matrix;
    }

    Matrix &operator*(const Matrix &operation_matrix) const {
        return Matrix(*this) *= operation_matrix;
    }

    Matrix &operator^(const uint64_t operation_pow) const {
        return Matrix(*this) ^= operation_pow;
    }

    friend istream &operator>>(istream &stream, Matrix &target) {
        for (size_t height_index = 0; height_index < target.height; height_index++) {
            for (size_t width_index = 0; width_index < target.width; width_index++) {
                stream >> target.data[height_index][width_index];
            }
        }
        return stream;
    }

    friend ostream &operator<<(ostream &stream, Matrix &target) {
        for (size_t height_index = 0; height_index < target.height; height_index++) {
            stream << "[";
            for (size_t width_index = 0; width_index < target.width; width_index++) {
                stream << target.data[height_index][width_index];
                stream << (width_index + 1 == target.width ? "]\n" : ", ");
            }
        }
        return stream;
    }

    vector<T> &operator[](const size_t index) { return data[index]; }

    size_t height_size() { return height; }

    size_t width_size() { return width; }
};


int main() {
    ll N, K;
    cin >> N >> K;
    Matrix<modint> input(N);
    cin >> input;
    input ^= K;
    modint ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            ans += input[i][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256