#include <bits/stdc++.h>
#define int long long

using namespace std;


int mod = 998244353;

int binpow(int a,int b,int p) {
    if (p == 0) {
        return a;
    }
    if (p % 2 == 0) {
        int Y = binpow(a, b, p / 2) % mod;
        return (Y * Y) % mod;
    }
    return (b * (binpow(a, b, p - 1)) % mod) % mod;
}

int cost(vector<int> &a) {
    int ans = 0;
    for (int i = 0; i < (int) a.size(); i++) {
        int T = 1;
        ans += binpow(T, a[i], (i + 1)) % mod;
        ans %= mod;
    }
    return ans%mod;
}

struct YY {
    int OO = -1;
};

map<pair<int,int>, YY> AA;
long long n;

void rec(vector<int> pere,int op,int CCC) {
    if (op == 30) {
        return;
    }
    int U = CCC%mod;

    for (int i = 1; i <= 2; i++) {
        if (i == 1) {
            if (AA[{U, 1}].OO != -1) {
                continue;
            }

            reverse(pere.begin(), pere.end());
            int T1 = cost(pere) % mod;
            AA[{U % mod, i}].OO = T1 % mod;
            rec(pere, op + 1, T1);
            reverse(pere.begin(), pere.end());
        }
        if (i == 2) {
            if (AA[{U, 2}].OO != -1) {
                continue;
            }
            vector<int> YY;
            for (int j = 0; j < n; j++) {
                YY.push_back((n - pere[j] + 1));
            }

            int T2 = cost(YY) % mod;
            AA[{U % mod, i}].OO = T2 % mod;
            rec(YY, op + 1, T2);
        }

        if (i == 3) {
            if (AA[{U, 3}].OO != -1) {
                continue;
            }
            vector<int> Q(n);
            for (int j = 0; j < n; j++) {
                Q[pere[j] - 1] = j + 1;
            }

            int T3 = cost(Q) % mod;
            AA[{U % mod, i}].OO = T3;
            rec(Q, op + 1, T3);
        }
    }
}

void solve() {

    int q;
    cin >> n >> q;
    vector<int> p;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        p.push_back(a);
    }

    int P = cost(p) % mod;
    int UUU = 0;
    //cout<<P<<endl<<endl;

    rec(p, UUU, P);
    /*
    for (auto i:AA) {
        cout<<i.first.first<<" "<<i.first.second<<" "<<i.second.OO<<endl;
    }
    cout<<endl;
    */
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a;
        P = AA[{P % mod, a}].OO % mod;

        cout << P % mod << " ";
    }
    cout << endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
