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

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int inf = 1e9L;
const int mod = 998244353;
const int maxn = 1e5;

ll mod_bin_pow(ll x, ll pow) {
    if (!pow) return 1;
    ll ans = mod_bin_pow(x, pow / 2);
    ans = (ans * ans) % mod;
    if (pow & 1) ans = (ans * x) % mod;
    return ans;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];
    ll ans = 0, ans_rev = 0;
    for (int i = 0; i < n; ++i) {
        ans += mod_bin_pow(p[i], i + 1);
        ans %= mod;
    }
    reverse(all(p));
    for (int i = 0; i < n; ++i) {
        ans_rev += mod_bin_pow(p[i], i + 1);
        ans_rev %= mod;
    }
    bool is_rev = false;
    for (int _ = 0; _ < q; ++_) {
        int type; cin >> type;
        if (type == 1) {
            is_rev ^= 1;
        }else if (type == 2) {
            is_rev ^= 1;
        }
        cout << (is_rev ? ans_rev : ans) << " ";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
}