#pragma GCC optimize("O3,unroll-loops")
#include <string>
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const ll mod = 998244353;

ll fpow (ll a, ll n) {
    ll ans = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            ans = (ans * a) % mod;
            --n;
        }
        a = (a * a) % mod;
        n /= 2;
    }
    return ans;
}

void Solve () {
    int n, q;
    cin >> n >> q;
    vector<ll>a(n);
    for (ll& i : a) {
        cin >> i;
    }
    ll ans0 = 0;
    for (int i = 0; i < n; ++i) {
        ans0 += fpow(a[i], i + 1);
        ans0 %= mod;
    }
    vector<ll>a1 = a;
    reverse(a1.begin(), a1.end());
    ll ans1 = 0;
    for (int i = 0; i < n; ++i) {
        ans1 += fpow(a1[i], i + 1);
        ans1 %= mod;
    }
    vector<ll>a2 = a;
    for (int i = 0; i < n; ++i) {
        a2[i] = n - a2[i] + 1;
    }
    ll ans2 = 0;
    for (int i = 0; i < n; ++i) {
        ans2 += fpow(a2[i], i + 1);
        ans2 %= mod;
    }
    vector<ll>a3(n);
    for (int i = 0; i < n; ++i) {
        a3[a[i] - 1] = i + 1;
    }
    ll ans3 = 0;
    for (int i = 0; i < n; ++i) {
        ans3 += fpow(a3[i], i + 1);
        ans3 %= mod;
    }
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (i % 2 == 1) {
            cout << ans0 << ' ';
            continue;
        }
        if (t == 1) {
            cout << ans1 << ' ';
        }
        if (t == 2) {
            cout << ans2 << ' ';
        }
        if (t == 3) {
            cout << ans3 << ' ';
        }
    }
}

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