#include<iostream>
#pragma GCC optimize("Ofast")
using namespace std;

using ll = long long;
using ld = long double;

const ll infl = (ll)4e18 + 100;
const int infi = (int)1e9 + 100;
const int maxn = (int)1e6 + 10;
const int mod = 998244353;

ll n, q;
ll p[maxn][2];
ll ans[3][2];

inline ll bpow(ll a, ll x) {
    if (x == 0)
        return 1;

    if (x % 2 == 0)
        return bpow((a * a) % mod, x / 2);
    return (a * bpow(a, x - 1)) % mod;
}

inline void solve() {
    cin >> n >> q;
    for (ll i = 1; i <= n; ++i)
        cin >> p[i][0];

    for (ll i = 1; i <= n; ++i)
        ans[0][0] = (ans[0][0] + bpow(p[i][0], i)) % mod;
    for (ll i = 1; i <= n; ++i)
        ans[0][1] = (ans[0][1] + bpow(p[n - i + 1][0], i)) % mod;

    for (ll i = 1; i <= n; ++i)
        ans[1][0] = (ans[1][0] + bpow(p[i][0], i)) % mod;
    for (ll i = 1; i <= n; ++i)
        ans[1][1] = (ans[1][1] + bpow(n - p[i][0] + 1, i)) % mod;

    for (ll i = 1; i <= n; ++i)
        ans[2][0] = (ans[2][0] + bpow(p[i][0], i)) % mod;
    for (ll i = 1; i <= n; ++i)
        p[p[i][0]][1] = i;
    for (ll i = 1; i <= n; ++i)
        ans[2][1] = (ans[2][1] + bpow(p[i][1], i)) % mod;

    ll rev = 0;

    while (q--) {
        ll tp; cin >> tp;
        rev = 1 - rev;

        cout << ans[tp - 1][rev] << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t_ = 1; // cin >> t_;
    while (t_--) {
        solve();
        cout << '\n';
    }

    return 0;
}