#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#define int long long
#define pll pair <int, int>
#define f first
#define s second
#define all(A) A.begin(), A.end()
#define rall(A) A.rbegin(), A.rend()
#define oset ordered_set
#define omultiset ordered_multiset
#define skip continue
#pragma GCC target("avx2")
#pragma GCC optmize("O3")
#pragma GCC optmize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 5e5 + 5, MOD = 998244353;
int p[N], b[N];

int bin_pow(int x, int n) {
    int res = 1;
    while (n) {
        if ((n & 1)) res = res * x % MOD;
        n >>= 1;
        x = x * x % MOD;
    }
    return res;
}

int scan() {
    int x; cin >> x;
    return x;
}

string read() {
    string s; cin >> s;
    return s;
}

void SLAVA_MORDOVII() {
    int n = scan(), q = scan();
    vector <int> Q(n + 1);
    for (int i = 0; i < n; i++) p[i + 1] = scan();
    for (int i = 0; i < q; i++) b[i + 1] = scan();
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++) {
        sum1 += bin_pow(p[i], i);
        if (sum1 >= MOD) sum1 -= MOD;
        sum2 += bin_pow(n + 1 - p[i], i);
        if (sum2 >= MOD) sum2 -= MOD;
    }
    for (int i = 1; i <= q; i++) {
        if (b[i] == 1) cout << sum1 << ' ';
        else {
            cout << sum2 << ' ';
            swap(sum2, sum1);
        }
    }
}

int32_t main() {
    SLAVA_MORDOVII();
}