#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;

using ll = long long;

// template <class T> using ordered_set = tree<T, nullptr, less<T>, rb_tree_tag, tree_node_statistics_update>;

const ll inf = ll(1e18) + 2;
const ll mod = 998244353;

struct node {
    ll x;
    ll p;

    node(ll x_ = -inf, ll p_ = 0) {
        x = x_;
        p = p_;
    }
};

node c(node a, node b) {
    node j;
    j.x = a.x + b.x;
    j.p = 0;
    return j;
}

struct st {

};

ll bp(ll a, ll n) {
    if (n == 0) {
        return 1 % mod;
    }
    ll k = bp(a, n / 2);
    if (n % 2 == 0) {
        return (k * k) % mod;
    }
    return (((k * k) % mod) * a) % mod;
}

ll f(vector<ll> &a) {
    ll res = 0;
    for (ll i = 0; i < ll(a.size()); i++) {
        res += bp(a[i] + 1, i + 1);
        res %= mod;
    }
    return res;
}

inline void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<vector<vector<ll>>> ans(2, vector<vector<ll>> (2, vector<ll> (2, 0)));
    for (ll i = 0; i < 2; i++) {
        for (ll j = 0; j < 2; j++) {
            for (ll w = 0; w < 2; w++) {
                vector<ll> b = a;
                if (w == 1) {
                    vector<ll> p(n);
                    for (ll k = 0; k < n; k++) {
                        p[b[k]] = k;
                    }
                    b = p;
                }
                if (i == 1) {
                    reverse(b.begin(), b.end());
                }
                if (j == 1) {
                    for (ll k = 0; k < n; k++) {
                        b[k] = n - 1 - b[k];
                    }
                }
                ans[i][j][w] = f(b);
            }
        }
    }
    vector<ll> t(3, 0);
    for (ll qi = 0; qi < q; qi++) {
        ll x;
        cin >> x;
        x--;
        t[x] ^= 1;
        cout << ans[t[0]][t[1]][t[2]] << " ";
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}
