#include <experimental/random>
#include <bits/stdc++.h>

using namespace std;
//experimental::randint(1, 10);
#define ll long long

ll MOD = 998244353;
ll INF = 1e18;
ll MX = 1e6 + 4;

ll step(ll v,ll ind) {
    if (ind == 0) {
        return 1;
    }
    if (ind % 2 == 0) {
        ll x = step(v, ind / 2);
        return (x * x) % MOD;
    }
    return (step(v, ind - 1) * v) % MOD;
}

ll sum(vector<ll> &s) {
    ll sum = 0;
    for (ll i = 0; i < (ll) s.size(); i++) {
        sum += step(s[i], i + 1);
        sum %= MOD;
    }
    return sum;
}


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

void rec2(vector<ll> &s) {
    ll n = (ll) s.size();
    for (ll i = 0; i < n; i++) {
        s[i] = n + 1 - s[i];
    }
}

void rec3(vector<ll> &s) {
    ll n = (ll) s.size();
    vector<ll> z = s;
    for (ll i = 0; i < n; i++) {
        s[z[i] - 1] = i + 1;
    }
}

void get(ll x, vector<ll> &s) {
    if (x == 1) {
        rec1(s);
    }
    if (x == 2) {
        rec2(s);
    }
    if (x == 3) {
        rec3(s);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, tt;
    cin >> n >> tt;
    vector<ll> p(n), q(tt);
    for (ll i = 0; i < n; i++) { cin >> p[i]; }
    for (ll i = 0; i < tt; i++) {
        cin >> q[i];
    }
    vector<vector<vector<ll> > > h(2, vector<vector<ll> >(2, vector<ll>(2)));
    for (ll i = 0; i < 2; i++) {
        for (ll j = 0; j < 2; j++) {
            for (ll e = 0; e < 2; e++) {
                auto z = p;
                if (i == 1) {
                    rec1(z);
                }
                if (j == 1) {
                    rec2(z);
                }
                if (e == 1) {
                    rec3(z);
                }
                h[i][j][e] = sum(z);
            }
        }
    }
    vector<ll> f(3);
    for (ll i = 0; i < tt; i++) {
        ll x = q[i];
        f[x - 1]++;
        cout << h[f[0] % 2][f[1] % 2][f[2] % 2] << " ";
    }
}
