#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 mem[8];
    for (int x = 0; x < 8; ++x) {
        mem[x] = 0;
        int z[n];
        for (int i = 0; i < n; ++i) {
            z[i] = a[i];
        }
        if (x & 1) {
            reverse(z, z + n);
        }
        if (x & 2) {
            for (int i = 0; i < n; ++i) {
                z[i] = {n + 1 - z[i]};
            }
        }
        if (x & 4) {
            int cp[n];
            for (int i = 0; i < n; ++i) {
                cp[z[i] - 1] = i + 1;
            }
            for (int i = 0; i < n; ++i) {
                z[i] = cp[i];
            }
        }
        for (int i = 0; i < n; ++i) {
            mem[x] = mem[x] + bmpow(z[i], i + 1);
        }
    }
    int x = 0;
    for (int k = 0; k < q; ++k) {
        int b;
        cin >> b;
        x ^= 1ll << (b - 1);
        cout << mem[x].v << ' ';
    }
}
signed main() {
    solve();
    return 0;
}