#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = __int128_t;
using ull = unsigned long long;
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
constexpr int mod = 998244353;
ll fpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int calc_cost(const vector<int> &p) {
    int cost = 0;
    for (int i = 0; i < (int) p.size(); ++i) {
        cost = (cost + fpow(p[i], i + 1)) % mod;
    }
    return cost;
}
void pere(vector<int> &p) {
    int n = (int) p.size();
    for (int i = 0; i < n; ++i) p[i] = n - p[i] + 1;
}
void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int &i : p) cin >> i;
    int ans[2][2];
    int rev = 0, per = 0;
    ans[0][0] = calc_cost(p);
    pere(p);
    ans[0][1] = calc_cost(p);
    reverse(all(p));
    ans[1][1] = calc_cost(p);
    pere(p);
    ans[1][0] = calc_cost(p);
    while (q--) {
        int b;
        cin >> b;
        if (b == 1) rev ^= 1;
        else if (b == 2) per ^= 1;
        cout << ans[rev][per] << " ";
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
