#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998244353;

long long bp(int a, int b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2) {
        return bp(a, b - 1) * a % MOD;
    }
    long long tmp = bp(a, b / 2);
    return tmp * tmp % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> b(q);
    for (int i = 0; i < q; i++) {
        cin >> b[i];
    }
    vector<long long> ans(4);
    for (int i = 0; i < n; i++) {
        ans[0] = (ans[0] + bp(a[i], i + 1)) % MOD;
    }
    reverse(a.begin(), a.end());
    vector<int> c = a;
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        ans[1] = (ans[1] + bp(c[i], i + 1)) % MOD;
    }
    for (int i = 0; i < n; i++) {
        a[i] = n - a[i] + 1;
        c[i] = n - c[i] + 1;
    }
    for (int i = 0; i < n; i++) {
        ans[2] = (ans[2] + bp(a[i], i + 1)) % MOD;
    }
    for (int i = 0; i < n; i++) {
        ans[3] = (ans[3] + bp(c[i], i + 1)) % MOD;
    }
    int pos = 0;
    for (int i = 0; i < q; i++) {
        if (b[i] == 1) {
            if (pos % 2 == 0) {
                pos++;
            } else {
                pos--;
            }
        } else {
            if (pos >= 2) {
                pos -= 2;
            } else {
                pos += 2;
            }
        }
        cout << ans[pos] << ' ';
    }
}
