// #pragma GCC optimize("O3,fast-math,unroll-loops")
#include <bits/stdc++.h>

#define i64 int64_t
#define vi vector<int>
#define vvi vector<vi>
#define vc vector
#define vb vc<bool>
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;

template <typename T>

istream& operator>>(istream& in, vector<T> &a) {
    for (T &el : a) in >> el;
    return in;
}

template <typename T>

ostream& operator<<(ostream& out, vector<T> a) {
    for (T &el : a) out << el << " ";
    return out;
}

const int MOD = 998244353;

int pw(int a, int b) {
    if (!b) return 1;
    if (b & 1) return 1ll * pw(a, b - 1) * a % MOD;
    return pw(1ll * a * a % MOD, b / 2);
}


void solve() {
    int n, q;
    cin >> n >> q;
    vi p(n);
    cin >> p;
    vi b(q);
    cin >> b;
    int pv = -1;
    int nw = -1;
    vi mp(4);
    for (int i = 0; i < 4; ++i) {
        if (i & 1) {
            reverse(all(p));
        }
        if (i & 2) {
            for (int &el : p) el = n - el + 1;
        }

        int ans = 0;
        for (int j = 0; j < n; ++j) {
            ans += pw(p[j], j + 1);
            ans %= MOD;
        }

        mp[i] = ans;

        if (i & 1) {
            reverse(all(p));
        }
        if (i & 2) {
            for (int &el : p) el = n - el + 1;
        }
    }
    int x = 0;
    for (int i = 0; i < q; ++i) {
        if (b[i] == 1) {
            x ^= 1;
        } else if (b[i] == 2) {
            x ^= 2;
        }
        cout << mp[x] << '\n';
    }
}

int32_t main() {
    // freopen("inputb.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}