#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
const int mod=998244353;
const int mex=55;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
#define int long long
int power(int a,int b)
{
	int ans=1,f=a;
	while(b)
	{
		if(b&1ll) ans=ans*f%mod;
		f=f*f%mod;
		b=b>>1ll;
	}
	return ans%mod;
}
veci v1[mex];
int vis[mex];
int cp;
void dfs(int n)
{
	//cout<<n<<endl;
	vis[n]=1;
	cp++;
	fo(i,0,sz(v1[n]))
	if(vis[v1[n][i]]==0)dfs(v1[n][i]);
}

signed main()
{
	int fact[55];
	fact[0]=1;
	fo(i,1,mex)fact[i]=fact[i-1]*i%mod;
	int n,k;
	cin>>n>>k;
	int a[n][n];
	fo(i,0,n)
	fo(j,0,n)
	{
		cin>>a[i][j];
	}
	int c[n]={0},r[n]={0};
	fo(j,0,n)
	{
		int cnt=0;
		fo(k1,0,j)
		{
			int fg=0;
			fo(i,0,n)
			{
				if((a[i][j]+a[i][k1])<=k) fg++;
			}
			if(fg==n) 
			{
				v1[j].pb(k1);
			v1[k1].pb(j);
			}
		}
		//c[j]=cnt;
	}
	int ans=1;
	fo(i,0,n)
 	if(vis[i]==0) 
	{ dfs(i);
	ans=ans*fact[cp]%mod;
	cp=0;
	}
	fo(i,0,n+1)
	{
		vis[i]=0;
		v1[i].clear();
	}
	fo(j,0,n)
	{
		int cnt=0;
		fo(k1,0,j)
		{
			int fg=0;
			fo(i,0,n)
			{
				if((a[j][i]+a[k1][i])<=k) fg++;
			}
			if(fg==n) 
			{v1[j].pb(k1);
			v1[k1].pb(j);
			}
		}
		//r[j]=cnt;
	}
	fo(i,0,n)
 	if(vis[i]==0) 
	{ dfs(i);
	ans=ans*fact[cp]%mod;
	cp=0;
	}
	
	cout<<ans<<endl;



}
#include<ctime>
#include<cstdio>
#include<cctype>
#define ll long long
using namespace std;
const ll N=55;
const ll HgS=998244353;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
ll f[N],sz[N],vis[N];
ll n,k,x,jc[N],a[N][N];
void start(){
	for(ll i=1;i<=n;++i){
		f[i]=i;
		sz[i]=1;
		vis[i]=0;
	}
}
ll get(ll x){
	if(x==f[x])
		return x;
	f[x]=get(f[x]);
	return f[x];
}
void merge(ll x,ll y){
	x=get(x);
	y=get(y);
	if(x==y)
		return;
	f[y]=x;
	sz[x]+=sz[y];
}
int main() {
	#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	x=1;
	jc[0]=1;
	n=read();
	k=read();
	for(ll i=1;i<=n;++i)
		jc[i]=jc[i-1]*i%HgS;
	for(ll i=1;i<=n;++i)
	for(ll j=1;j<=n;++j)
		a[i][j]=read();
	start();
	for(ll i=1;i<=n;++i)
	for(ll j=1;j<=n;++j){
		ll flg=1;
		for(ll l=1;l<=n;++l){
			if(a[i][l]+a[j][l]>k){
				flg=0;
				break;
			}
		}
		if(flg)
			merge(i,j);
	}
	for(ll i=1;i<=n;++i){
		get(i);
		if(vis[f[i]])
			continue;
		vis[f[i]]=1;
		x*=jc[sz[f[i]]];
		x%=HgS;
	}
	start();
	for(ll i=1;i<=n;++i)
	for(ll j=1;j<=n;++j){
		ll flg=1;
		for(ll l=1;l<=n;++l){
			if(a[l][i]+a[l][j]>k){
				flg=0;
				break;
			}
		}
		if(flg)
			merge(i,j);
	}
	for(ll i=1;i<=n;++i){
		get(i);
		if(vis[f[i]])
			continue;
		vis[f[i]]=1;
		x*=jc[sz[f[i]]];
		x%=HgS;
	}
	printf("%lld",x);
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}