#pragma GCC optimize("O3,unroll-loops")
#include<bits/extc++.h>
#pragma GCC target("avx2,popcnt")

#define all(_a) (_a.begin(), _a.end())
#define sz(_a) int32_t(_a.size())
#define ll long long
#define fi first
#define se second
#define deb(_a) cerr << __LINE__ << ' ' << (#_a) << ": " << _a << '\n';

using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto i: v) out << i << ' ';
    return out;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (auto &i: v) in >> i;
    return in;
}

inline void solve();

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

vector<int> fun(vector<int> a, int x) {
    // cerr << x << '\n';
    int n = sz(a);
    if (x & 1) {
        vector<int> b(n);
        for (int i = 0; i < n; i++) {
            b[i] = a[n - i - 1];
        }
        a = b;
    }
    // deb(a);
    if (x & 2) {
        vector<int> b(n);
        for (int i = 0; i < n; i++) {
            b[i] = n - a[i] + 1;
        }
        a = b;
    }
    // deb(a);
    if (x & 4) {
        vector<int> b(n);
        for (int i = 0; i < n; i++) {
            b[a[i] - 1] = i + 1;
        }
        a = b;
    }
    // deb(a);
    return a;
}

int mod = 998244353;

int power(ll a, ll pw) {
    ll ans = 1;
    while (pw) {
        if (pw & 1) {
            ans = (ans * a) % mod;
        }
        a = a * a % mod;
        pw /= 2;
    }
    return ans;
}

int get_ans(vector<int> a) {
    ll res = 0;
    for (int i = 0; i < sz(a); i++) {
        res = ((ll)res + power(a[i], i + 1)) % mod;
    }
    return res;
}

inline void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    cin >> a;
    vector<vector<int>>  b(8, vector<int> (n));
    b[0] = a;
    for (int i = 1; i < 8; i++) {
        b[i] = fun(a, i);
    }
    vector<int> ans(8);
    for (int i = 0; i < 8; i++) ans[i] = get_ans(b[i]);
    int cur = 0;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        x--;
        cur = cur ^ (1 << x);
        cout << ans[cur] << ' ';
        // cerr << cur << '\n';
    }
    // deb(ans);
    // for (auto i: b) deb(i);
}