#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
using ll = long long;
using namespace std;
// #pragma GCC optimize("O3, unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
//  using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
//  tree_order_statistics_node_update>;
const int mod = 998244353;
int modpow(int a, int x) {
    if (x == 0)
        return 1;
    if (x % 2 == 0) {
        int tmp = modpow(a, x / 2) % mod;
        return tmp * tmp % mod;
    } else {
        return (a % mod) * modpow(a, x - 1) % mod;
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (auto& x : p) cin >> x;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += modpow(p[i], i + 1) $ mod;
        ans = ans % mod;
    }
    int ans2 = 0;
    reverse(p.begin(), p.end());
    for (int i = 0; i < n; ++i) {
        ans2 += modpow(p[i], i + 1) % mod;
        ans2 = ans2 % mod;
    }
    for (int i = 1; i <= n; ++i) {
        p[i - 1] = n - p[i - 1] + 1;
    }
    int ans3 = 0;
    for (int i = 0; i < n; ++i) {
        ans3 += modpow(p[i], i + 1) % mod;
        ans3 = ans3 % mod;
    }
    int ans4 = 0;
    reverse(p.begin(), p.end());
    for (int i = 0; i < n; ++i) {
        ans4 += modpow(p[i], i + 1) % mod;
        ans4 = ans4 % mod;
    }
    int c1, c2 = 0;
    while (q--) {
        int b;
        cin >> b;
        if (b == 1)
            c1++;
        if (b == 2)
            c2++;
        if (c1 % 2 == 1 && c2 % 2 == 1) {
            cout << ans3 << ' ';
        } else if (c1 % 2 == 1 && c2 % 2 == 0) {
            cout << ans2 << ' ';
        } else if (c1 % 2 == 0 && c2 % 2 == 0) {
            cout << ans << ' ';
        } else {
            cout << ans4 << ' ';
        }
    }

    return 0;
}
