#include <bits/stdc++.h>
using namespace std;
#define int long long
const int m = 998244353;


int binpow(int x, int p) {
    if (p == 1)
        return x;
    int res = binpow(x, p / 2);
    res = res * res % m;
    if (p % 2)
        res = res * x % m;
    return res;
}


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    vector<int> b(q);
    for (int i = 0; i < q; i++)
        cin >> b[i];
    
    vector<int> ans(2);
    for (int i = 1; i <= n; i++)
        ans[0] = (ans[0] + binpow(a[i], i)) % m;
    vector<int> p(n + 1);
    if (b[0] == 1) {
        for (int i = 1; i <= n; i++)
            p[i] = a[n - i + 1];
        swap(a, p);
        for (int i = 1; i <= n; i++)
            ans[1] = (ans[1] + binpow(a[i], i)) % m;
    } else if (b[0] == 2) {
        for (int i = 1; i <= n; i++)
            p[i] = n - a[i] + 1;
        swap(a, p);
        for (int i = 1; i <= n; i++)
            ans[1] = (ans[1] + binpow(a[i], i)) % m;
    } else {
        for (int i = 1; i <= n; i++)
            p[a[i]] = i;
        swap(a, p);
        for (int i = 1; i <= n; i++)
            ans[1] = (ans[1] + binpow(a[i], i)) % m;
    }

    int x = 0;
    for (int c : b) {
        x = 1 - x;
        cout << ans[x] << ' ';
    }
}


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
    return 0;
}
