// #pragma GCC optimize("Ofast")

#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define all(x) x.begin(), x.end()

#ifdef DEBUG
    #define debug(x) {cout << __func__ << ":" << __LINE__ << " " << #x << " = " << x << "\n";};
    #define debugw(x) {cout << __func__ << ":" << __LINE__ << " " << x << "\n";};
#else
    #define debug(x)
    #define debugw(x)
#endif

const int mod = 998'244'353;

int n, q;
vector<int> p;

int binpow(int a, int n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        int res = binpow(a, n / 2);
        return ((ll)res * res) % mod;
    } else {
        int res = binpow(a, n - 1);
        return ((ll)res * a) % mod;
    }
}

int calc(vector<int> &p) {
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += binpow(p[i], i + 1);
        res %= mod;
    }
    return res;
}

void solve() {
    cin >> n >> q;
    p.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int state[2];

    state[0] = calc(p);
    reverse(all(p));
    state[1] = calc(p);

    int cur = 0;
    for (int i = 0; i < q; i++) {
        int b;
        cin >> b;
        if (b <= 2) {
            cur ^= 1;
        }
        cout << state[cur] << " ";
    }
    cout << "\n";
}

signed main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // cout << set_precision(8) << fixed;

    // ll T;
    // cin >> T;
    // while (T--) solve();

    solve();
}