#include <iostream>
using namespace std;
#define int long long
struct res {
    int v;
    res () : v(0) {}
    res(int v) : v(v) {}
};
const int mod = 998244353;
res operator+(res a, res b) {
    return {a.v + b.v >= mod? a.v + b.v - mod : a.v + b.v};
}
res operator-(res a, res b) {
    return {a.v - b.v < 0? a.v - b.v + mod : a.v - b.v};
}

res operator*(res a, res b) {
    return {a.v * b.v % mod};
}
res bmpow(res a, int n) {
    if (n == 0) return {1};
    if (n & 1) {
        return  a * bmpow(a, n - 1);
    }
    return bmpow(a * a, n / 2);
}
void solve() {
    int n, q;
    cin >> n >> q;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    res ans(0);
    res mem[4];
    for (int i = 0; i < n; ++i) {
        mem[0] = mem[0] + bmpow(a[i], i + 1);
    }
    reverse(a, a + n);
    for (int i = 0; i < n; ++i) {
        mem[1] = mem[1] + bmpow(a[i], i + 1);
    }
    reverse(a, a + n);
    for (int i = 0; i < n; ++i) {
        mem[2] = mem[2] + bmpow({n - a[i] + 1}, i + 1);
    }
    int z[n];
    for (int i = 0; i < n; ++i) {
        z[a[i] - 1] = i + 1;
    }
    for (int i = 0; i < n; ++i) {
        mem[3] = mem[3] + bmpow(z[i], i + 1);
    }
    int x = 0;
    for (int k = 0; k < q; ++k) {
        int b;
        cin >> b;
        x ^= b;
        cout << mem[x].v << ' ';
    }
}
signed main() {
    solve();
    return 0;
}