//#define _GLIBCXX_DEBUG
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

#define int long long

using namespace std;
using ll = long long;
using ld = long double;

const int INTI = 2e9 + 5, MAXN = 1e5 + 1, MOD = 998244353;
const ll INF = 4e18 + 5;

int binpow(int a, int b) {
    int pr = 1;
    while (b) {
        if (b & 1)
            pr = (pr * a) % MOD;
        b >>= 1;
        a = (a * a) % MOD;
    }
    return pr;
}

int ans[2][2];

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (auto& i : a)
        cin >> i;
    for (int i = 0; i < n; ++i)
        ans[0][0] = (ans[0][0] + binpow(a[i], i + 1)) % MOD;
    for (int i = 0; i < n / 2; ++i)
        swap(a[i], a[n - 1 - i]);
    for (int i = 0; i < n; ++i)
        ans[0][1] = (ans[0][1] + binpow(a[i], i + 1)) % MOD;
    for (int i = 0; i < n; ++i)
        a[i] = n - a[i] + 1;
    for (int i = 0; i < n; ++i)
        ans[1][1] = (ans[1][1] + binpow(a[i], i + 1)) % MOD;
    for (int i = 0; i < n / 2; ++i)
        swap(a[i], a[n - 1 - i]);
    for (int i = 0; i < n; ++i)
        ans[1][0] = (ans[1][0] + binpow(a[i], i + 1)) % MOD;
    //cout << ans[0][0] << ' ' << ans[0][1] << ' ' << ans[1][0] << ' ' << ans[1][1] << '\n';
    int p1 = 0, p2 = 0;
    while (q--) {
        int b;
        cin >> b;
        if (b == 1) {
            p2 = 1 - p2;
        } else {
            p1 = 1 - p1;
        }
        cout << ans[p1][p2] << ' ';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}
