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

using namespace std;
using namespace __gnu_pbds;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2,bmi,popcnt")


// #define double long double
#define int long long
#define endl "\n"
#define ordered_set  tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

constexpr int MOD = 998244353;
constexpr int INF = 2e9;
constexpr int K = 3;
constexpr int P = 31;
constexpr double eps = 1e-9;
constexpr int MOD1 = (1ll << 61) - 1;

inline int pls(int a, int b) {
    if (a + b >= MOD1) return a + b - MOD1;
    return a + b;
}

inline int mns(int a, int b) {
    return pls(a, MOD1 - b);
}

inline int umn(int a, int b) {
    __int128 c = __int128(a) * b;
    return pls(c & MOD1, c >> 61);
}

int binpow(int n, int k, int mod) {
    if (!k) return 1;
    if (k & 1) return n * binpow(n, k ^ 1, mod) % mod;
    int c = binpow(n, k >> 1, mod);

    return c * c % mod;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<int> sum((1 << 3));
    for (int mask = 0; mask < (1 << 3); mask++) {
        vector<int> cur = p;
        if (mask & 1) {
            vector<int> s = cur;
            for (int i = 1; i <= n; i++) {
                s[i - 1] = cur[n - i];
            }
            cur = s;
        }
        if (mask & 4) {
            vector<int> s = cur;
            for (int i = 0; i < n; i++) {
                s[cur[i] - 1] = i + 1;
            }
            cur = s;
        }
        if (mask & 2) {
            vector<int> s = cur;
            for (int i = 0; i < n; i++) {
                s[i] = n - cur[i] + 1;
            }
            cur = s;
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            res += binpow(cur[i - 1], i, MOD);
            res %= MOD;
        }
        sum[mask] = res;
    }
    int cur = 0;
    while (q--) {
        int b;
        cin >> b;
        b--;
        cur ^= (1 << b);
        cout << sum[cur] << endl;
    }

}