#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update<>>

const int MOD = 998244353;

vector<int> obr(vector<int> p) {
    vector<int> q(p.size());
    for (int i = 0; i < p.size(); i++) {
        q[p[i] - 1] = i + 1;
    }
    return q;
}

int binpow(int x, int pw) {
    if (pw == 0) {
        return 1;
    }
    if (pw % 2) {
        return (binpow(x, pw - 1) * x) % MOD;
    }
    int hlf = binpow(x, pw / 2);
    return (hlf * hlf) % MOD;
}

int calc(vector<int> a) {
    int ans = 0;

    for (int i = 0; i < a.size(); i++) {
        ans = (ans + binpow(a[i], i + 1)) % MOD;
    }
    return ans;
}

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

    vector<int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int df = calc(a);
    vector<int> tr(3);

    tr[2] = calc(obr(a));
    reverse(all(a));
    tr[0] = calc(a);
    reverse(all(a));
    for (int i = 0; i < n; i++) {
        a[i] = n + 1 - a[i];
    }
    tr[1] = calc(a);


    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        if (i % 2 == 1) {
            cout << df << " ";
            continue;
        }
        cout << tr[x - 1] << " ";
    }
}


signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
}
