#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace chrono;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T, typename Cmp = less<T>>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, Cmp,
__gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
inline int sz(const T& x) {
    return (int)x.size();
}

const int MAXN = 1e5;
const int INF = 2e9;
const int ALPH = 26;
const int MAXLOG = 20;
const ll MOD = 998244353;
const ld EPS = 1e-8;

const ull SEED = steady_clock::now().time_since_epoch().count();
mt19937_64 rnd(67);

ll binpow(ll x, ll p) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            res = (res * x) % MOD;
        }
        x = (x * x) % MOD;
        p >>= 1;
    }
    return res;
}

void rev(vector<ll>& p) {
    reverse(p.begin(), p.end());
}

void flip(vector<ll>& p) {
    for (auto& i : p) {
        i = sz(p) + 1 - i;
    }
}

void pow_minus1(vector<ll>& p) {
    vector<ll> q(sz(p));
    for (int i = 0; i < sz(p); i++) {
        q[p[i] - 1] = i + 1;
    }
    p = q;
}

void solve() {
    ll n, queries;
    cin >> n >> queries;
    vector<ll> p(n);
    for (auto& i : p) {
        cin >> i;
    }
    // if (n == 5 && p == vector<ll>({5, 3, 1, 4, 2})) {
    //     cout << "293 303 3225 215 317 3209";
    //     return;
    // }
    vector<ll> ans(8, 0);
    for (ll mask = 0; mask < 8; mask++) {
        vector<ll> q = p;
        vector<ll> r(n);
        iota(r.begin(), r.end(), 1);
        if (mask >> 2 & 1) {
            if (mask >> 0 & 1) {
                flip(q);
            }
            if (mask >> 1 & 1) {
                rev(q);
                flip(r);
            }
            for (ll i = 0; i < n; i++) {
                ans[mask] = (ans[mask] + binpow(r[i], q[i])) % MOD;
            }
        } else {
            if (mask >> 0 & 1) {
                rev(q);
            }
            if (mask >> 1 & 1) {
                flip(q);
            }
            for (ll i = 0; i < n; i++) {
                ans[mask] = (ans[mask] + binpow(q[i], i + 1)) % MOD;
            }
        }
    }
    ll mask = 0;
    while (queries--) {
        ll type;
        cin >> type; type--;
        mask ^= 1 << type;
        cout << ans[mask] << ' ';
    }
}

int main() {
    #ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_cases = 1;
    // cin >> test_cases;
    while (test_cases--) solve();
    return 0;
}
