#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=200010;

//Union-Find木

struct UnionFind {
    vector< int > data;

    UnionFind() = default;

    explicit UnionFind(size_t sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return data[k] = find(data[k]);
    }

    int size(int k) {
        return -data[find(k)];
    }

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

signed main(){
    ll n,k;cin>>n>>k;
    vector<ll>fac(n*n+1);
    fac[0]=1;
    REP(i,1,n+1){
        fac[i]=fac[i-1]*i%mod;
    }
    UnionFind uf1(n);
    UnionFind uf2(n);
    vector<vector<ll> >a(n,vector<ll>((n)));
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
        }
    }
    rep(i,n){
        REP(j,i+1,n){
            bool f=1;
            rep(l,n){
                if(a[i][l]+a[j][l]>k)f=0;
            }
            if(f)uf1.unite(i,j);
        }
    }
    rep(i,n){
        REP(j,i+1,n){
            bool f=1;
            rep(l,n){
                if(a[l][i]+a[l][j]>k)f=0;
            }
            if(f)uf2.unite(i,j);
        }
    }
    ll ans=1;
    vector<ll>used1(n);
    vector<ll>used2(n);
    rep(i,n){
        if(used1[uf1.find(i)])continue;
        used1[uf1.find(i)]=1;
        ans=ans*fac[uf1.size(i)]%mod;
    }
    rep(i,n){
        if(used2[uf2.find(i)])continue;
        used2[uf2.find(i)]=1;
        ans=ans*fac[uf2.size(i)]%mod;
    }
    cout<<ans<<endl;
}
#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';
}

