//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef tuple<int,int,int> T;
typedef tuple<ll,ll,ll> TL;
ll mod = 1000000007;
ll mod2 = 998244353;

struct UnionFind {
    int _n;
    vector<int> par, siz;

    UnionFind(int n) : par(n), siz(n, 1) {
        _n = n;
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    int unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return -1;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        // rx>=ry rxが親
        siz[rx] += siz[ry];
        par[ry] = rx;  //rxにryを結合
        return rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return siz[root(x)];
    }
};

ll fraction (ll n){
    if (n==1) return 1;
    return n * fraction(n-1) % mod2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin>>n>>k;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,0,n){
        rep(j,0,n){
            cin>>a[i][j];
        }
    }

    UnionFind uf1(n);
    ll ans = 1;

    rep(i,0,n){
        rep(j,0,n){
            ll f = 0;
            if (i<j){
                f = 1;
                rep(s,0,n){
                    if (a[i][s]+a[j][s]>k){
                        f = 0;
                    }
                }
            }
            if (f) {
                uf1.unite(i,j);
            }
        }
        
    }

    rep(i,0,n){
        if (uf1.par[i]==i){
            ans = ans * fraction(uf1.size(i)) %mod2;
        }
    }

    UnionFind uf2(n);

    rep(i,0,n){
        rep(j,0,n){
            ll f = 0;
            if (i<j){
                f = 1;
                rep(s,0,n){
                    if (a[s][i]+a[s][j]>k){
                        f = 0;
                    }
                }
            }
            if (f) {
                uf2.unite(i,j);
            }
        }
    }
    
    rep(i,0,n){
        if (uf2.par[i]==i){
            ans = ans * fraction(uf2.size(i)) %mod2;
        }
    }

    cout<<ans<<endl;
}
#include <iostream>
#include <algorithm>
#define MOD 998244353
int N, K;
int A[50][50];
int row_ok[50][50];
int col_ok[50][50];
long long num[51];
using namespace std;

long long calc(int line_ok[][50]) {
    long long ans = 1;
    int group[50];
    int groupN[50];
    for (int i=0; i<N; i++) group[i] = i;
    for (int i=0; i<N; i++) {
        groupN[i] = 0;
    }

    for (int _=0; _<=N; _++) {
        for (int i=0; i<N; i++) {
            for (int j=0; j<N; j++) {
                if (line_ok[i][j] == 1) {
                    int x = min(group[i], group[j]);
                    group[i] = group[j] = x;
                }
            }
        }
    }
    for (int i=0; i<N; i++) {
        groupN[group[i]]++;
    }
    for (int i=0; i<N; i++) {
        if (groupN[i] > 0) {
            ans *= num[groupN[i]];
            ans %= MOD;
        }
    }
    return ans;
}
int main() {
    {
        long long x = 1;
        for (int i=1; i<51; i++)
        {
            x *= i;
            x %= MOD;
            num[i] = x;
        }
    }

    cin >> N >> K;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            cin >> A[i][j];
        }
    }

    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            bool ok = true;
            for (int c=0; c<N; c++) {
                if (A[c][i] + A[c][j] > K) {
                    ok = false;
                    break;
                } 
            }
            if (ok) col_ok[i][j] = 1;
        }
    }
    
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            bool ok = true;
            for (int c=0; c<N; c++) {
                if (A[i][c] + A[j][c] > K) {
                    ok = false;
                    break;
                } 
            }
            if (ok) row_ok[i][j] = 1;
        }
    }

    // row
    cout << (calc(row_ok) * calc(col_ok)) % MOD << endl;

    return 0;
}