#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const long long mod = 998244353;
long long n;

long long bin(long long a, long long b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2 == 0) {
        long long res = bin(a, b / 2);
        return (res * res) % mod;
    }
    return (a * bin(a, b - 1)) % mod;
}

vector<long long> f(vector<long long> p) {
    vector<long long> res(n);
    for (long long i = 0; i < n; i++) {
        res[i] = n - p[i] + 1;
    }
    return res;
}


long long get(vector<long long> id, vector<long long> p) {
    long long res = 0;
    for (long long i = 0; i < n; i++) {
        res += bin(p[i], id[i]);
        res %= mod;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long q;
    cin >> n >> q;
    vector<long long> p(n), id(n);
    for (long long i = 0; i < n; i++) {
        cin >> p[i];
        id[i] = i + 1;
    }
    vector<long long> ans(8);
    for (long long i = 0; i < 8; i++) {
        vector<long long> res = p;
        vector<long long> res_id = id;
        if (i & 2) {
            res = f(res);
        }
        if (i & 1) {
            res_id = f(res_id);
        }
        if (i & 4) {
            ans[i] = get(res, res_id);
        } else {
            ans[i] = get(res_id, res);
        }
    }
    long long cur = 0;
    for (long long i = 0; i < q; i++) {
        long long t;
        cin >> t;
        t--;
        t = (1 << t);
        if (t != 4) {
            if (cur & 4) {
                t ^= 3;
            }
        }
        cur ^= t;
        cout << ans[cur] << '\n';
    }
}