#include <bits/stdc++.h>

using namespace std;

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

const ll inf = 1e18 + 1e16;
const ll inf_t = 1e9 + 7;
const ll mod = 998244353;

#define int ll

int bin_pow(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return bin_pow(a, b - 1) * a % mod;

    int temp = bin_pow(a, b / 2);
    return temp * temp % mod;
}

void solve() {
    int n, q;
    cin >> n >> q;

    vector <vector <int>> p(8, vector <int> (n));
    for (int i = 0; i < n; ++i) {
        cin >> p[0][i];
        --p[0][i];
    }

    int st[8];
    for (int mask = 0; mask < 8; ++mask) {
        if (mask & 1) {
            for (int i = 0; i < n; ++i) {
                p[mask][i] = p[mask ^ 1][n - i - 1];
            }
        } else if (mask & 2) {
            for (int i = 0; i < n; ++i) {
                p[mask][i] = n - p[mask ^ 2][i] - 1;
            }
        } else if (mask & 4) {
            for (int i = 0; i < n; ++i) {
                p[mask][p[mask ^ 4][i]] = i;
            }
        }

        st[mask] = 0;
        for (int i = 0; i < n; ++i) {
            st[mask] += bin_pow(p[mask][i] + 1, i + 1);
        }
        st[mask] %= mod;

    }

    int mask = 0;
    for (int i = 0; i < q; ++i) {
        int op;
        cin >> op;

        mask ^= (1 << (op - 1));
        cout << st[mask] << " ";
    }
}

signed main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
