#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 (j == 1) {
                        reverse(b.begin(), b.end());
                    }
                    if (i == 1) {
                        for (ll k = 0; k < n; k++) {
                            b[k] = n - 1 - b[k];
                        }
                    }
                } else {
                    if ((i ^ (j & w)) == 1) {
                        reverse(b.begin(), b.end());
                    }
                    if (j ^ (i & w) == 1) {
                        for (ll k = 0; k < n; k++) {
                            b[k] = n - 1 - b[k];
                        }
                    }
                }
                ans[i][j][w] = f(b);
            }
        }
    }
    map<vector<ll>, ll> ans2;
    vector<ll> c = {0, 1, 2};
    do {
        vector<ll> b = a;
        for (ll i = 0; i < 3; i++) {
            if (c[i] == 0) {
                reverse(b.begin(), b.end());
            } else if (c[i] == 1) {
                    for (ll k = 0; k < n; k++) {
                        b[k] = n - 1 - b[k];
                    }
            } else if (c[i] == 2) {
                    vector<ll> p(n);
                    for (ll k = 0; k < n; k++) {
                        p[b[k]] = k;
                    }
                    b = p;
            }
        }
        ans2[c] = f(b);
    } while (next_permutation(c.begin(), c.end()));


    c = {0, 1, 2};
    do {
        vector<ll> b = a;
        for (ll i = 0; i < 2; i++) {
            if (c[i] == 0) {
                reverse(b.begin(), b.end());
            } else if (c[i] == 1) {
                    for (ll k = 0; k < n; k++) {
                        b[k] = n - 1 - b[k];
                    }
            } else if (c[i] == 2) {
                    vector<ll> p(n);
                    for (ll k = 0; k < n; k++) {
                        p[b[k]] = k;
                    }
                    b = p;
            }
        }
        ans2[{c[0], c[1]}] = f(b);
    } while (next_permutation(c.begin(), c.end()));

    c = {0, 1, 2};
    do {
        vector<ll> b = a;
        for (ll i = 0; i < 1; i++) {
            if (c[i] == 0) {
                reverse(b.begin(), b.end());
            } else if (c[i] == 1) {
                    for (ll k = 0; k < n; k++) {
                        b[k] = n - 1 - b[k];
                    }
            } else if (c[i] == 2) {
                    vector<ll> p(n);
                    for (ll k = 0; k < n; k++) {
                        p[b[k]] = k;
                    }
                    b = p;
            }
        }
        ans2[{c[0]}] = f(b);
    } while (next_permutation(c.begin(), c.end()));

    ans2[{}] = f(a);

    vector<ll> t(3, 0);
    string t2;
    for (ll qi = 0; qi < q; qi++) {
        ll x;
        cin >> x;
        x--;
        t[x] ^= 1;
        t2.push_back(x + '0');
        bool f2 = 1;
        while (ll(t2.size()) >= 2 && f2 == 1) {
            ll k = ll(t2.size());
            f2 = 0;
            if (t2[k - 2] == t2[k - 1]) {
                t2.pop_back();
                t2.pop_back();
                f2 = 1;
            } else {
                if (k >= 3) {
                    if (t2[k - 1] != '2' && t2[k - 3] == t2[k - 1]) {
                        t2.pop_back();
                        t2.erase(t2.begin() + k - 3);
                        f2 = 1;
                        continue;
                    }
                    if (t2.substr(k - 3, 3) == "202") {
                        t2.pop_back();
                        t2.pop_back();
                        t2.pop_back();
                        t2 += "1";
                        f2 = 1;
                        continue;
                    }
                    if (t2.substr(k - 3, 3) == "212") {
                        t2.pop_back();
                        t2.pop_back();
                        t2.pop_back();
                        t2 += "0";
                        f2 = 1;
                        continue;
                    }
                    if (t2.substr(k - 3, 3) == "102") {
                        t2.pop_back();
                        t2.pop_back();
                        t2.pop_back();
                        f2 = 1;
                        continue;
                    }
                    if (t2.substr(k - 3, 3) == "201") {
                        t2.pop_back();
                        t2.pop_back();
                        t2.pop_back();
                        f2 = 1;
                        continue;
                    }
                    if (t2.substr(k - 3, 3) == "120") {
                        t2.pop_back();
                        t2.pop_back();
                        t2.pop_back();
                        t2 += "2";
                        f2 = 1;
                        continue;
                    }
                    if (t2.substr(k - 3, 3) == "021") {
                        t2.pop_back();
                        t2.pop_back();
                        t2.pop_back();
                        t2 += "2";
                        f2 = 1;
                        continue;
                    }
                }
            }
        }
        // cout << "> " << t2 << endl;
        vector<ll> e;
        for (auto i : t2) {
            e.push_back(i - '0');
        }
        cout << ans2[e] << " ";
    }
    cout << endl;
}

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