#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long bin_pow(long long a, int b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        long long x = bin_pow(a, b / 2) % MOD;
        return (x * x) % MOD;
    }
    return (a * bin_pow(a, b - 1)) % MOD;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n, qw; cin >> n >> qw;
    vector<int> p(n + 1);
    bool fl = true;
    for (int i = 1; i <= n; i++) cin >> p[i];
    vector<int> q(qw, 0);
    for (auto& x : q) cin >> x;
    vector<vector<long long>> ans(2, vector<long long>(2, 0));
    for (int i = 1; i <= n; i++) {
        ans[0][0] += bin_pow(p[i], i) % MOD;
    }
    for (int i = n; i >= 1; i--) {
        ans[1][0] += bin_pow(p[i], i) % MOD;
    }
    vector<int> g(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        g[i] = n - p[i] + 1;
    }
    p = g;
    for (int i = 1; i <= n; i++) {
        ans[0][1] += bin_pow(p[i], i) % MOD;
    }
    for (int i = n; i >= 1; i--) {
        ans[1][1] += bin_pow(p[i], i) % MOD;
    }

    int j = 0, h = 0;
    for (int i = 0; i < qw; i++) {
        int x = q[i];
        if (x == 1) j += 1;
        if (x == 2) h += 1;
        j %= 2;
        h %= 2;
        cout << ans[j][h] % MOD << " ";
    }
}