#include <bits/stdc++.h>

using namespace std;
#define int long long
const int mod = 998244353;
int exp(int a, int b) {
    if (b == 0) {
        return 1;
    }
    if (b & 1) {
        return a * exp(a, b - 1) % mod;
    }
    return exp(a * a % mod, b / 2);
}
void bad() {
    int n, q;
    cin >> n >> q;
    vector <int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector <int> cur(n);
    int ans[2][2][2];
    for (int f1 = 0; f1 < 2; ++f1) {
        for (int f2 = 0; f2 < 2; ++f2) {
            for (int f3 = 0; f3 < 2; ++f3) {
                int v = 0;
                for (int i = 0; i < n; ++i) {
                    v += exp(p[i], i + 1);
                    v %= mod;
                }
                ans[f1][f2][f3] = v;
                for (int i = 0; i < n; ++i) {
                    cur[p[i] - 1] = i + 1;
                }
                swap(cur, p);
            }
            for (int &v : p) {
                v = (n + 1 - v);
            }
        }
        reverse(p.begin(), p.end());
    }
    vector <int> counter(3);
    for (int i = 0; i < q; ++i) {
        int b;
        cin >> b;
        --b;
        counter[b] ^= 1;
        cout << ans[counter[0]][counter[1]][counter[2]] << ' ';
    }
    cout << '\n';
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    bad();
}