#include "iostream"
#include "algorithm"
#include "vector"
#include "queue"
using namespace std;
#define int long long
#define all(arr) arr.begin(), arr.end()
#define _lg(x) (63 - __builtin_clzll(x))
constexpr int maxn = 200'010;
constexpr int mod = 998'244'353;
int arr[maxn]{};
int dop_arr[maxn]{};
int fpm(int x, int n, int m) {
    int ans = 1;
    while (n) {
        if (n & 1) ans = ans * x % m;
        x = x * x % m;
        n >>= 1;
    }
    return ans;
}

int price(int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += fpm(arr[i], i + 1, mod);
    }
    return sum % mod;
}
int value[2][2][2]{};
void solve() {
    int n, q; cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                value[i][j][k] = price(n);
                reverse(arr, arr + n);
            }
            for (int l = 0; l < n; l++) {
                arr[l] = n + 1 - arr[l];
            }
        }
        for (int l = 0; l < n; l++) {
            dop_arr[arr[l] - 1] = l + 1;
        }
        for (int l = 0; l < n; l++) {
            arr[l] = dop_arr[l];
        }
    }
    int ind[3]{0, 0, 0};
    for (int i = 0; i < q; i++) {
        int b; cin >> b; ind[3 - b] ^= 1;
        cout << value[ind[0]][ind[1]][ind[2]] << ' ';
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1; //cin >> t;
    while (t--) {
        solve();
    }
}