#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long

using namespace __gnu_pbds;
using namespace std;

int md = 998244353;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int pw(int a, int b) {
    if (b ==0) return 1;
    if (b == 1) return a;
    if (b % 2 == 0) {
        int h = pw(a, b / 2);
        return h * h % md;
    }
    return a * pw(a, b - 1) % md;
}

int recalc(vector<int> a) {
    int n = a.size();
    int an = 0;
    for (int i = 0; i < n; ++i) {
        an += pw(a[i], i + 1);
        an %= md;
    }
    return an;
}

signed main() {
    int n, q1;
    cin >> n >> q1;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    map<vector<int>, int> m_;
    vector<vector<int>> per(100, vector<int> (3));
    m_[a] = 1;
    int cr = 2;
    map<vector<int>, int> mp;
    queue<vector<int>> q;
    q.push(a);
    vector<int> zn(100);
    while (!q.empty()) {
        vector<int> k = q.front();
        q.pop();
        int nm = m_[k];
        mp[k] = recalc(k);
        zn[nm] = mp[k];
        reverse(k.begin(), k.end());
        if (m_[k] == 0) {
            q.push(k);
            m_[k] = cr++;
            mp[k] = -1;
        }
        per[nm][0] = m_[k];
        reverse(k.begin(), k.end());
        for (int i = 0; i < k.size(); ++i) {
            k[i] = k.size() + 1 - k[i];
        }
        if (m_[k] == 0) {
            q.push(k);
            m_[k] = cr++;
            mp[k] = -1;
        }
        per[nm][1] = m_[k];
        for (int i = 0; i < k.size(); ++i) {
            k[i] = k.size() + 1 - k[i];
        }
        vector<int> nw(k.size());
        for (int i = 0; i < k.size(); ++i) {
            nw[k[i] - 1] = i + 1;
        }
        if (m_[nw] == 0) {
            q.push(nw);
            m_[nw] = cr++;
            mp[nw] = -1;
        }
        per[nm][2] = m_[nw];
    }
    int now = 1;
    for (int i = 0; i < q1; ++i) {
        int x;
        cin >> x;
        x--;
        now = per[now][x];
        //cout << zn[now] << ' ';
        cout << zn[now] << '\n';
    }
}