#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using vl = __int128_t;
using ld = long double;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll mod = 998244353;
ll pw(ll a, ll b) {
    ll r = 1;
    while (b) {
        if (b & 1) r = (r * a) % mod;
        a = (a * a) % mod, b >>= 1;
    }
    return r;
}
ll f(vector<ll>& p) {
    ll ans = 0;
    for (ll i = 0; i < p.size(); i++) ans = (ans + pw(p[i], i + 1)) % mod;
    return ans;
}
void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> p(n), q(n);
    for (ll& x : p) cin >> x;
    ll f1 = f(p);
    reverse(all(p));
    ll f2 = f(p);
    reverse(all(p));
    vector<ll> wp = p;
    for (ll& x : p) x = n - x + 1;
    ll f3 = f(p);
    p = wp;
    for (ll i = 0; i < n; i++) q[p[i] - 1] = i + 1;
    ll f4 = f(q);
    ll s1 = 0, s2 = 0, s3 = 0;
    while (m--) {
        ll tp;
        cin >> tp;
        vector<ll> q = p;
        if (tp == 1) {
            s1 ^= 1;
        } else if (tp == 2) {
            s2 ^= 1;
        } else {
            s3 ^= 1;
        }
        if (s1) cout << f2 << ' ';
        else if (s2) cout << f3 << ' ';
        else if (s3) cout << f4 << ' ';
        else cout << f1 << ' ';
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
