//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
// gp_hash_table<int, int>table;
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
//find_by_order(x) - итератор на k по величине элемент
//order_of_key(x) - колво элементов в множестве строго меньших чем наш элемент
struct segment_tree {
    segment_tree(ll lb, ll rb) : lb(lb), rb(rb), pos(lb) {
        if (lb != rb) {
            ll mid = (lb + rb) / 2;
            l = new segment_tree(lb, mid);
            r = new segment_tree(mid + 1, rb);
        }
    }

    void set(ll ps, ll x) {
        if (lb == rb) {
            mn = x;
            return;
        }
        ll mid = (lb + rb) / 2;
        if (ps <= mid) {
            l->set(ps, x);
        } else {
            r->set(ps, x);
        }
        if (l->mn <= r->mn) {
            mn = l->mn;
            pos = l->pos;
        } else {
            mn = r->mn;
            pos = r->pos;
        }
    }

    ll mn = LLONG_MAX, pos = -1;
    ll lb, rb;
    segment_tree *l = nullptr, *r = nullptr;
};

const ll MOD = 998244353;
ll binpow(ll a, ll n) {
    if (n == 0) {
        return 1;
    }
    if (n == 1) {
        return a % MOD;
    }
    ll g = binpow(a, n / 2);
    if (n % 2 == 0) {
        return (g * g) % MOD;
    }
    return (((g * g) % MOD) * a) % MOD;
}

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> p(n);
    for (ll i = 0; i < n; ++i) {
        cin >> p[i];
    }
    ll sm = 0, sm1 = 0, sm2 = 0, sm3 = 0;
    for (ll i = 0; i < n; ++i) {
        sm += binpow(p[i], i + 1);
        sm %= MOD;
    }
    vector<vector<ll>>dp(3, vector<ll>(3));
    dp[0][0] = sm;
    vector<ll>g = p;
    reverse(g.begin(), g.end());
    for (ll i = 0; i < n; ++i) {
        sm1 += binpow(g[i], i + 1);
        sm1 %= MOD;
    }
    dp[1][0] = sm1;
    for (ll i = 0; i < n; ++i) {
        g[i] = n - p[i] + 1;
    }
    for (ll i = 0; i < n; ++i) {
        sm2 += binpow(g[i], i + 1);
        sm2 %= MOD;
    }
    dp[1][2] = sm2;
    sm1 = 0, sm2 = 0;
    g = p;
    for (ll i = 0; i < n; ++i) {
        p[i] = n - p[i] + 1;
    }
    for (ll i = 0; i < n; ++i) {
        sm2 += binpow(g[i], i + 1);
        sm2 %= MOD;
    }
    dp[2][0] = sm2;
    reverse(g.begin(), g.end());
    for (ll i = 0; i < n; ++i) {
        sm1 += binpow(g[i], i + 1);
        sm1 %= MOD;
    }
    dp[2][1] = sm1;
    ll st = 0, sc = 0;
    while (q--) {
        ll b;
        cin >> b;
        if (st == 0) {
            st = b;
        } else if (sc == 0) {
            sc = b;
        } else if (sc == b) {
            sc = 0;
        } else if (st == b) {
            st = sc;
            sc = 0;
        }
        cout<<dp[st][sc]<<' ';
    }
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
#ifndef LOCAL
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
#endif
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
