#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const long long mod = 998244353;
long long n;

long long bin(long long a, long long b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2 == 0) {
        long long res = bin(a, b / 2);
        return (res * res) % mod;
    }
    return (a * bin(a, b - 1)) % mod;
}

vector<long long> f1(vector<long long> p) {
    reverse(p.begin(), p.end());
    return p;
}
vector<long long> f2(vector<long long> p) {
    vector<long long> res(n);
    for (long long i = 0; i < n; i++) {
        res[i] = n - p[i] + 1;
    }
    return res;
}
vector<long long> f3(vector<long long> p) {
    vector<long long> res(n);
    for (long long i = 0; i < n; i++) {
        res[p[i] - 1] = i + 1;
    }
    return res;
}

long long f(vector<long long> p) {
    long long res = 0;
    for (long long i = 0; i < n; i++) {
        res += bin(p[i], i + 1);
        res %= mod;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long q;
    cin >> n >> q;
    vector<long long> p(n);
    for (long long i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<long long> ans(8);
    for (long long i = 0; i < 8; i++) {
        vector<long long> res = p;
        if (i & 1) {
            res = f1(res);
        }
        if (i & 2) {
            res = f2(res);
        }
        if (i & 3) {
            res = f3(res);
        }
        ans[i] = f(res);
    }
    long long cur = 0;
    for (long long i = 0; i < q; i++) {
        long long t;
        cin >> t;
        t--;
        t = (1 << t);
        cur ^= t;
        cout << ans[cur] << '\n';
    }
}