#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define asc(x) x.begin(), x.end()
#define des(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define ll long long
#define db long double
#define fori(a, b) for (int i = (a); i < (b); ++i)
#define forj(a, b) for (int j = (a); j < (b); ++j)

using namespace std;
// using namespace __gnu_pbds;
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(228);

const int MOD = 998244353;

int pw(int x, int y) {
    if (x == 1) return 1;
    if (y == 1) return x;

    int _x = pw(x, y / 2);

    _x = (1ll * _x * _x) % MOD;
    if (y % 2) {
        _x = (_x * x) % MOD;
    }

    return _x;
}

void solve() {
    int n, q; cin >> n >> q;

    vector<int> p(n);
    fori(0, n) cin >> p[i];

    vector<ll> sm(8);
    for (int swp = 0; swp < 2; ++swp) {
        for (int rev = 0; rev < 2; ++rev) {
            fori(0, n) {
                int cur = i + 1, val = p[i], mask = 0;

                if (swp) {
                    cur = n - i;
                    mask += 4;
                }

                if (rev) {
                    val = n - val + 1;
                    mask += 2;
                }

                sm[mask] += pw(val, cur);
                sm[mask + 1] += pw(cur, val);
            }
        }
    }

    int mask = 0;
    while (q--) {
        int x; cin >> x;

        x = 3 - x;

        if (x) {
            if (mask % 2) {
                if (x == 1) {
                    x = 2;
                } else {
                    x = 1;
                }
            }
        }

        mask ^= 1 << x;

        cout << sm[mask] % MOD << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int tt = 1;
    while (tt--) {
        solve();
        cout << "\n";
    }
}