#include <bits/stdc++.h>
#define LL long long
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }


const int N  = 55,P = 998244353;
LL fac[N],ans = 1;
int a[N][N],n,k,fa[N],siz[N];
inline int Find(int x){ return x == fa[x] ? x : (fa[x] = Find(fa[x])); }
inline void Merge(int x,int y){ x = Find(x),y = Find(y),fa[x] = y; if (x!=y) siz[y]+=siz[x]; }
inline void solve(){
	int i,j,x,flag;
	for (i = 1; i <= n; ++i) fa[i] = i,siz[i] = 1;
	for (i = 1; i <= n; ++i) for (j = i+1; j <= n; ++j){
		flag = 1;
		for (x = 1; x <= n; ++x) if (a[i][x] + a[j][x] > k) flag = 0;
		if (flag) Merge(i,j);
	}
	for (i = 1; i <= n; ++i) if (i == Find(i)) ans = ans * fac[siz[i]] % P;
}
int main(){
	static int b[N][N];
	int i,j;
	fac[0] = 1;
	for (i = 1; i <= 54; ++i) fac[i] = fac[i-1] * i % P;
	cin >> n >> k;
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) cin >> a[i][j];
	solve();
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) b[i][j] = a[i][j];
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) a[i][j] = b[j][i];
	solve();
	cout << ans << '\n';
	return 0;
}
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;

int main() {
	string n;
	cin >> n;
	int k;
	cin >> k;
	int nn = n.size();
	vector<vector<long long int>> v(nn + 1, vector<long long int>(k + 1, 0));
	unordered_set<int> us;
	long long int res = 0;
	const int mod = 1e9 + 7;
	for (int i = 1; i <= nn; i++) {
		// v[already checked][how many used]
		if (i > 1) {
			v[i][1] += 15;
		}
		for (int j = 0; j <= k; j++) {
			// v[i - 1][j] -> v[i][j or j + 1];
			v[i][j] += v[i - 1][j] * j;
			if (j > 0) v[i][j] += v[i - 1][j - 1] * (16 - j + 1);
			v[i][j] %= mod;
		}

		char c = n[i - 1];
		int nc = (c <= '9' and c >= '0' ? c - '0' : c - 'A' + 10);
		for (int j = (i == 1 ? 1 : 0); j < nc; j++) {
			int e = 0;
			if (us.count(j) == 0) e = 1;
			if (us.size() + e <= k) {
				v[i][us.size() + e]++;
			}
		}
		us.insert(nc);
	}
	if (us.size() == k) res++;
	for (int i = k; i <= k; i++) {
		res += v[nn][i];
	}
	res %= mod;
	cout << res << endl;
}

