#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define db long double
#define MX LLONG_MAX
#define MN LLONG_MIN
#define gcd __gcd
#define lcm(a, b) (a / gcd(a, b) * b)

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int MOD = 998244353;

vector<int> f0(const int n, const vector<int>& p) {
    vector<int> q(n);
    for (int i = 0; i < n; i++) q[i] = p[n - 1 - i];
    return q;
}

vector<int> f1(const int n, const vector<int>& p) {
    vector<int> q(n);
    for (int i = 0; i < n; i++) q[i] = n - p[i] + 1;
    return q;
}

vector<int> f2(const int n, const vector<int>& p) {
    vector<int> q(n);
    for (int i = 0; i < n; i++) q[p[i] - 1] = i + 1;
    return q;
}

int bin_pow(int base, int pow) {
    if (pow == 0) return 1;
    if (pow % 2) return bin_pow(base, pow - 1) * base % MOD;
    int val = bin_pow(base, pow / 2);
    return val * val % MOD;
}

int f(const int n, const vector<int>& p) {
    int res = 0;
    for (int i = 0; i < n; i++) res = (res + bin_pow(p[i], i + 1)) % MOD;
    return res;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n, q;
    cin >> n >> q;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

//    while (q--) {
//        int type;
//        cin >> type;
//        type--;
//
//        if (type == 0) a = f0(n, a);
//        if (type == 1) a = f1(n, a);
//        if (type == 2) a = f2(n, a);
//
//        cout << f(n, a) << " ";
//    }

    int ans[8];
    for (int mask = 0; mask < 8; mask++) {
        vector<int> v = a;
        if ((mask >> 0) & 1) v = f0(n, v);
        if ((mask >> 1) & 1) v = f1(n, v);
        if ((mask >> 2) & 1) v = f2(n, v);
        ans[mask] = f(n, v);
    }

    int mask = 0;
    while (q--) {
        int l;
        cin >> l;
        l--;

        mask ^= (1 << l);
        cout << ans[mask] << " ";
    }
}
