#include <bits/stdc++.h>
using namespace std;
#define int long long
const int m = 998244353;


int binpow(int x, int p) {
    if (p == 1)
        return x;
    int res = binpow(x, p / 2);
    res = res * res % m;
    if (p % 2)
        res = res * x % m;
    return res;
}


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    vector<int> b(q);
    for (int i = 0; i < q; i++)
        cin >> b[i];
    
    vector<vector<int>> ans(2, vector<int>(2));

    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++)
        ans[0][0] = (ans[0][0] + binpow(a[i], i)) % m;

    for (int i = 1; i <= n; i++)
        p[i] = a[n - i + 1];
    swap(a, p);
    for (int i = 1; i <= n; i++)
        ans[1][0] = (ans[1][0] + binpow(a[i], i)) % m;
    
    for (int i = 1; i <= n; i++)
        p[i] = n - a[i] + 1;
    swap(a, p);
    for (int i = 1; i <= n; i++)
        ans[1][1] = (ans[1][1] + binpow(a[i], i)) % m;

    for (int i = 1; i <= n; i++)
        p[i] = a[n - i + 1];
    swap(a, p);
    for (int i = 1; i <= n; i++)
        ans[0][1] = (ans[0][1] + binpow(a[i], i)) % m;

    int b1 = 0, b2 = 0;
    for (int c : b) {
        if (c == 1) {
            b1 = 1 - b1;
        } else if (c == 2) {
            b2 = 1 - b2;
        }
        cout << ans[b1][b2] << ' ';
    }
}


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
    return 0;
}
