#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 400005;
ll fac[55];
int d[55];
int v[55][55];
int fi(int x) {
    return d[x] < 0 ? x : d[x] = fi(d[x]);
}
void merge(int x,int y) {
    x = fi(x);
    y = fi(y);
    if (x == y) return;
    d[x] += d[y];
    d[y] = x;
}
void go() {
    int n, tar;
    cin >> n >> tar;
    fac[0] = 1;
    f1(50) {
        fac[i] = fac[i - 1] * i % mod;
    }
    f1(n) {
        fr(j,1,n+1) {
            cin >> v[i][j];
        }
    }
    memset(d, -1, sizeof(d));
    fr(j,1,n+1) {
            fr(k,1,n+1) {
                int f = 0;
                fr(i,1,n+1) {
                    if (v[i][j] + v[i][k] > tar) {
                        f = 1;
                        break;
                    }
                }
                if (!f) {
                    merge(j,k);
                }
            }
        }
    ll ans = 1;
    f1(n) {
        if (d[i] < 0) {
            ans *= fac[-d[i]];
            ans %= mod;
        }
    }
    memset(d, -1, sizeof(d));
    //f1(n) {
        fr(j,1,n+1) {
            fr(k,1,n+1) {
                int f = 0;
                fr(i,1,n+1) {
                    if (v[j][i] + v[k][i] > tar) {
                        f = 1;
                        break;
                    }
                }
                if (!f) {
                    merge(j,k);
                }
            }
        }
    //}
    f1(n) {
        if (d[i] < 0) {
            ans *= fac[-d[i]];
            ans %= mod;
        }
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}
//un_coder        
#include<bits/stdc++.h>
typedef long long ll;
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define inf 1e18
using namespace std;
void solve();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
    freopen("output.txt", "w", stdout);
    #endif
   
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }
    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}
void solve()
{
    int n,q;
    cin>>n>>q;
    vector<ll> a(n),low(n);
    for(auto &it:a)
        cin>>it;
    for(int i=0; i<n; i++)
        low[i]=a[i]-(i+1);
    for(int i=0; i<q; i++)
    {
        ll k;
        cin>>k;
        int idx=lower_bound(all(low),k)-low.begin();
        if(idx==n)
            cout<<a[n-1]+(k-low[n-1])<<"\n";
        else
            cout<<a[idx]-(low[idx]-k+1)<<"\n";
    }
}
