#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define start auto st = clock()
#define finish auto fin = clock(); cerr << 1000 * (fin - st) / (ld)CLOCKS_PER_SEC << endl
const ll mod2 = 998244353;

using namespace std;

void print(vector<int> &a) {
    for (auto x : a) cout << x << ' ';
    cout << '\n';
}

// #define mtask
// #define int ll

ll fp(ll n, ll k) {
    if (k == 0) return 1;
    if (k & 1) return (fp(n, k - 1) * n) % mod2;
    ll rs = fp(n, k / 2);
    return (rs * rs) % mod2;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    vector<int> inds(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        --p[i];
        inds[i] = i;
    }

    auto flip = [&]() {
        for (int i = 0; i < n; ++i) {
            p[i] = n - 1 - p[i];
        }
    };

    auto flipf = [&]() {
        for (int i = 0; i < n; ++i) {
            inds[i] = n - 1 - inds[i];
        }
    };

    auto score = [&]() -> ll {
        ll rs = 0;

        for (int i = 0; i < n; ++i) {
            ll cur = fp(p[i] + 1, inds[i] + 1);
            rs += cur;
        }
        return rs % mod2;
    };

    auto scoref = [&]() -> ll {
        ll rs = 0;

        for (int i = 0; i < n; ++i) {
            ll cur = fp(inds[i] + 1, p[i] + 1);
            rs += cur;
        }
        return rs % mod2;
    };

    map<array<int, 3>, ll> ans;

    for (int ff = 0; ff < 2; ++ff) {
        for (int fn = 0; fn < 2; ++fn) {
            ans[{ff, fn, 0}] = score();
            ans[{ff, fn, 1}] = scoref();
            flip();
        }
        flipf();
    }

    int ff = 0, fn = 0, flp = 0;

    for (int i = 0; i < q; ++i) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            if (flp) {
                fn ^= 1;
            }
            else {
                ff ^= 1;
            }
        }
        else if (tp == 2) {
            if (flp) {
                ff ^= 1;
            }
            else {
                fn ^= 1;
            }
        }
        else {
            flp ^= 1;
        }
        // cout << mf << ' ' << mn << ' ' << ff << ' ' << fn << ' ' << flp << '\n';
        cout << ans[{ff, fn, flp}] << ' ';
        // cout << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
#ifdef mtask
    int t;
    cin >> t;
    while (t--)
#endif
        solve();
}