#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

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

const int MAXN = 1e5+50;
const int MOD = 998244353;
const int INF = 1e9;
const ll LLINF = 1e16;
const ld EPS = 1e-9;
const int LOGN = 25;

ll binpow(ll x, ll k) {
    if (k == 0) return 1;
    if (k % 2 == 0) {
        ll d = binpow(x, k/2) % MOD;
        return d*d%MOD;
    }
    return x*(binpow(x, k-1))%MOD;
}
int n, q;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> q;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    ll sum = 0, sum1 = 0, sum2 = 0, sum3 = 0;
    for (int i = 1; i <= n; i++) {
        sum = (sum + binpow(a[i], i))%MOD;
    }
    // 1
    for (int i = 1; i <= n; i++) {
        sum1 = (sum1 + binpow(a[n-i+1], i))%MOD;
    }

    // 2
    for (int i = 1; i <= n; i++) {
        sum2 = (sum2 + binpow(n-a[i]+1, i))%MOD;
    }

    // 3
    vector<int> b(n+1);
    for (int i = 1; i <= n; i++) {
        b[a[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        sum3 = (sum3 + binpow(b[i], i))%MOD;
    }

    q--; int t; cin >> t;
    if (t == 1) cout << sum1 << ' ';
    if (t == 2) cout << sum2 << ' ';
    if (t == 3) cout << sum3 << ' ';

    if (t == 1) for (int i = 1; i < q; i++) {
        cin >> t;
        cout << (i%2 ? sum : sum1) << ' ';
    }
    else if (t == 2) for (int i = 1; i < q; i++) {
        cin >> t;
        cout << (i%2 ? sum : sum2) << ' ';
    }
    else if (t == 3) for (int i = 1; i < q; i++) {
        cin >> t;
        cout << (i%2 ? sum : sum3) << ' ';
    }

}
