#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ar array

int n, k;
int arr[60][60];
int vis[60];
ll ans = 1;
int sz[60], dsu[60];
ll fact[60];
ll mod = 998244353;

int parent(int node){
    if(dsu[node] == node) return node;
    return dsu[node] = parent(dsu[node]);
}

void connect(int a, int b){
    a = parent(a), b = parent(b);
    if(a == b) return;
    dsu[a] = b, sz[b] += sz[a];
}

void comprow(int row){
    for(int i = 1; i <= n; i++){
        if(i == row) continue;
        bool f = 1;
        for(int j = 1; j <= n; j++){
            if(arr[row][j] + arr[i][j] > k) f = 0;
        }
        if(f) connect(row, i);
    }
}

void compcol(int col){
    for(int i = 1; i <= n; i++){
        if(i == col) continue;
        bool f = 1;
        for(int j = 1; j <= n; j++){
            if(arr[j][col] + arr[j][i] > k) f = 0;
        }
        if(f) connect(col, i);
    }
}

void factorial(){
    fact[0] = 1;
    for(int i = 1; i <= 50; i++) fact[i] = fact[i-1]*i, fact[i] %= mod;
}

void solve(){
    cin>>n>>k;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin>>arr[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        vis[i] = false, dsu[i] = i, sz[i] = 1;
    }
    for(int i = 1; i <= n; i++){
        comprow(i);
    }
    factorial();
    for(int i = 1; i <= n; i++){
        if(vis[ parent(i) ]) continue;
        vis[ parent(i) ] = true;
        ans *= fact[sz[ parent(i) ]], ans %= mod;
    }
    for(int i = 1; i <= n; i++){
        vis[i] = false, dsu[i] = i, sz[i] = 1;
    }
    for(int i = 1; i <= n; i++){
        compcol(i);
    }
    for(int i = 1; i <= n; i++){
        if(vis[ parent(i) ]) continue;
        vis[ parent(i) ] = true;
        ans *= fact[sz[ parent(i) ]], ans %= mod;
    }
    cout << ans << endl;
}


int main()
{
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,x,n) for(int i = x; i<=n; i++)
#define FORO(i,n) for(int i = 0; i<n; i++)
#define nl "\n"
#define sp " "
#define MOD 1000000007
#define INF 1000000000000000000
#define pb push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vpi vector<pair<int, int> >
#define vpl vector<pair<ll, ll> >
#define pi pair<int, int>
#define pl pair<ll, ll>
#define ff first
#define ss second

ll n, K, a[51][51], parent[51], sizes[51];

ll mod = 998244353;

ll fact(ll a){
	ll ans = 1;
	FOR(i,2,a){
		ans*=i;
		ans%=mod;
	}
	return ans;
}

void make_set(int v){
    parent[v] = v;
    sizes[v] = 1;
}

int find_set(int v){
    if(v==parent[v]) return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a!=b){
        if(sizes[a]<sizes[b]) swap(a, b);
        parent[b] = a;
        sizes[a]+=sizes[b];
    }
}

int main(){
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	cin>>n>>K;
	FORO(i,n){
		FORO(j,n) cin>>a[i][j];
	}
	FORO(i,n) make_set(i);
	FORO(i,n){
		FORO(j,n){
			bool fl = 1;
			FORO(k,n){
				if(a[k][i]+a[k][j]>K){
					fl = 0;
					break;
				}
			}
			if(fl) union_sets(i,j);
		}
	}
	ll ans = 1;
	FORO(i,n){
		if(parent[i]==i) ans = ans*fact(sizes[i])%mod;
	}
	FORO(i,n) make_set(i);
	FORO(i,n){
		FORO(j,n){
			bool fl = 1;
			FORO(k,n){
				if(a[i][k]+a[j][k]>K){
					fl = 0;
					break;
				}
			}
			if(fl) union_sets(i,j);
		}
	}
	FORO(i,n){
		if(parent[i]==i) ans = ans*fact(sizes[i])%mod;
	}
	cout<<ans;
	return 0;
}