#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll mod = 998244353;

ll binpow(ll a, ll b) {
    if (!b) return 1;
    if (b % 2 == 1) {
        return a * binpow(a, b - 1) % mod;
    }
    ll x = binpow(a, b / 2);
    return x * x % mod;
}

void solve() {
    ll n, q; cin >> n >> q;
    vector<ll> A(n);
    for (ll i = 0; i < n; ++i) cin >> A[i];
    ll res0 = 0, res1 = 0, res2 = 0, res3 = 0;
    vector<ll> A3(n), A1(n), A2(n);
    for (ll i = 0; i < n; ++i) {
        A1[i] = A[n - i - 1];
        res1 = (res1 + binpow(A1[i], i + 1));
    }
    for (ll i = 0; i < n; ++i) {
        A2[i] = n - A[i] + 1;
        res2 = (res2 + binpow(A2[i], i + 1));
    }
    for (ll i = 0; i < n; ++i) {
        A3[i] = A2[n - i - 1];
        res3 = (res3 + binpow(A3[i], i + 1));
    }
    for (ll i = 0; i < n; ++i) {
        res0 = (res0 + binpow(A[i], i + 1)) % mod;
    }
    ll tec = 0;
    while (q--) {
        ll t; cin >> t;
        if (tec == 0) {
            if (t == 1) {
                cout << res1 << ' ';
                tec = 1;
            }
            if (t == 2) {
                cout << res2 << ' ';
                tec = 2;
            }
        } else if (tec == 1) {
            if (t == 1) {
                cout << res0 << ' ';
                tec = 0;
            }
            if (t == 2) {
                cout << res3 << ' ';
                tec = 3;
            }
        } else if (tec == 2) {
            if (t == 1) {
                cout << res3 << ' ';
                tec = 3;
            }
            if (t == 2) {
                cout << res0 << ' ';
                tec = 0;
            }
        } else {
            if (t == 1) {
                cout << res2 << ' ';
                tec = 2;
            }
            if (t == 2) {
                cout << res1 << ' ';
                tec = 1;
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}