#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct union_find {
    vector<int> par, siz;
    union_find(int n) {
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }
    
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
 
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (siz[x] < siz[y]) {
            par[x] = y;
            siz[y] += siz[x];
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
        }
    }
    
    long long size(int x){
        return siz[find(x)];
    }

    bool same(int x, int y) {
        return (find(x) == find(y));
    }
};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n, k; cin >> n >> k;
    ll a[n][n]; zep(i, 0, n)zep(j, 0, n)cin >> a[i][j];
    
    union_find ufi(n), ufj(n);

    zep(x, 0, n){
        zep(y, x + 1, n){
            bool ok = true;
            zep(j, 0, n)if(a[x][j] + a[y][j] > k)ok = false;
            if(ok)ufj.unite(x, y);
        }
    }

    zep(x, 0, n){
        zep(y, x + 1, n){
            bool ok = true;
            zep(i, 0, n)if(a[i][x] + a[i][y] > k)ok = false;
            if(ok)ufi.unite(x, y);
        }
    }

    ll ans = 1;
    zep(i, 0, n){
        if(ufj.find(i) == i){
            rep(p, 1, ufj.size(i)){
                ans *= p;
                ans %= MOD;
            }
        }
    }

    zep(j, 0, n){
        if(ufi.find(j) == j){
            rep(p, 1, ufi.size(j)){
                ans *= p;
                ans %= MOD;
            }
        }
    }

    print(ans)
    return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <random>

const int32_t MOD = 998244353;

int32_t dfs(int32_t x, std::vector< bool > &vis, const std::vector< std::vector< bool > > &adj) {
    vis[x] = true;
    int32_t comp = 1;

    int32_t n = adj.size();
    for(int32_t i = 0; i < n; i++) {
        if(adj[x][i] && !vis[i]) {
            comp += dfs(i, vis, adj);
        }
    }

    return comp;
}

int32_t fact(int32_t x) {
    int32_t ans = 1;
    for(int32_t i = 2; i <= x; i++) {
        ans = (int64_t) ans * i % MOD;
    }
    return ans;
}

int32_t count(const std::vector< std::vector< bool > > &adj) {
    int32_t n = adj.size(), ans = 1;

    std::vector< bool > vis(n, false);
    for(int32_t i = 0; i < n; i++) {
        if(!vis[i]) {
            ans = (int64_t) ans * fact(dfs(i, vis, adj)) % MOD;
        }
    }

    return ans;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

    int32_t n, k;
    std::cin >> n >> k;
    
    std::vector< std::vector< int32_t > > v(n, std::vector< int32_t >(n));
    for(int32_t i = 0; i < n; i++) {
        for(int32_t j = 0; j < n; j++) {
            std::cin >> v[i][j];
        }
    }

    std::vector< std::vector< bool > > rows(n, std::vector< bool >(n, false));
    for(int32_t i1 = 0; i1 < n; i1++) {
        for(int32_t i2 = i1 + 1; i2 < n; i2++) {
            int32_t cnt = 0;
            for(int32_t j = 0; j < n; j++) {
                if(v[i1][j] + v[i2][j] <= k) {
                    cnt++;
                }
            }
            if(cnt == n) {
                rows[i1][i2] = true;
                rows[i2][i1] = true;
            }
        }
    }

    std::vector< std::vector< bool > > cols(n, std::vector< bool >(n, false));
    for(int32_t i1 = 0; i1 < n; i1++) {
        for(int32_t i2 = i1 + 1; i2 < n; i2++) {
            int32_t cnt = 0;
            for(int32_t j = 0; j < n; j++) {
                if(v[j][i1] + v[j][i2] <= k) {
                    cnt++;
                }
            }
            if(cnt == n) {
                cols[i1][i2] = true;
                cols[i2][i1] = true;
            }
        }
    }
    
    std::cout << (int64_t) count(rows) * count(cols) % MOD << '\n';
}

