#include<bits/stdc++.h>

#define ll long long

#define debug(x) cerr << (#x) << '=' << x << '\n';

using namespace std;

ll mod = 998244353;

ll bpow(ll a, ll b) {
    if (b == 1) return a;
    ll cur = bpow(a, b / 2);
    cur = (cur * cur) % mod;
    if ((b % 2) == 1) return (cur * a) % mod;
    return cur;
}

void q_1(vector<ll>& v, ll n) {
    for (ll i = 0; i < n / 2; i++) {
        swap(v[i], v[n - i - 1]);
    }
}

void q_2(vector<ll>& v, ll n) {
    for (ll i = 0; i < n; i++) {
        v[i] = n - v[i] + 1;
    }
}

void q_3(vector<ll>& v, ll n) {
    vector<ll> v1(n, 0);
    for (ll i = 0; i < n; i++) {
        v1[v[i] - 1] = i + 1;
    }
    for (ll i = 0; i < n; i++) {
        v[i] = v1[i];
    }
}

ll calc_cnt(vector<ll>& v, ll n) {
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
        cnt += bpow(v[i], i + 1);
        cnt = cnt % mod;
    }
    return cnt;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n, 0);
    for (ll i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<ll> cv(8, 0);
    cv[0] = calc_cnt(v, n);
    q_1(v, n);
    cv[1] = calc_cnt(v, n);
    q_2(v, n);
    cv[3] = calc_cnt(v, n);
    q_1(v, n);
    cv[2] = calc_cnt(v, n);
    q_2(v, n);
    q_3(v, n);
    cv[4] = calc_cnt(v, n);
    q_1(v, n);
    cv[5] = calc_cnt(v, n);
    q_2(v, n);
    cv[7] = calc_cnt(v, n);
    q_1(v, n);
    cv[6] = calc_cnt(v, n);
    ll c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    for (ll i = 0; i < k; i++) {
        cin >> c4;
        if (c4 == 1) {
            c1 += 1;
            if (c1 == 2) c1 = 0;
        } else if (c4 == 2) {
            c2 += 1;
            if (c2 == 2) c2 = 0;
        } else {
            swap(c1, c2);
            c3 += 1;
            if (c3 == 2) c3 = 0;
        }
        c4 = c1 + c2 * 2 + c3 * 4;
        cout << cv[c4] << ' ';
    }
    cout << '\n';
    return 0;
}