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

using namespace __gnu_pbds;
using namespace std;


#define rep(x) for (int rep_i = 0; rep_i < x; rep_i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define int long long
const ll MOD = 998244353;


mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int binpow(int a, int k) {
    if (k == 0)
        return 1;
    int b = binpow(a, k / 2);
    int z = (b * b) % MOD;
    if (k % 2 == 1)
        return (z * a) % MOD;
    return z;
}

void solve() {
    int n, qu;
    cin >> n >> qu;
    vector<int> p(n);
    rep(n)
        cin >> p[rep_i];
    int b;
    cin >> b;
    int st = 1;
    vector<int> q(n);
    int ans0 = 0;
    for (int i = 0; i < n; i++) {
        ans0 += binpow(p[i], (i + 1));
        ans0 %= MOD;
    }
    int ans1 = 0;
    if (b == 1) {
        for (int i = 0; i < n; i++)
            q[i] = p[n - i - 1];
        for (int i = 0; i < n; i++) {
            ans1 += binpow(q[i], (i + 1));
            ans1 %= MOD;
        }
    } else if (b == 2) {
        for (int i = 0; i < n; i++)
            q[i] = n - p[i] + 1;
        for (int i = 0; i < n; i++) {
            ans1 += binpow(q[i], (i + 1));
            ans1 %= MOD;
        }
    } else {
        for (int i = 0; i < n; i++)
            q[p[i] - 1] = i + 1;
        for (int i = 0; i < n; i++) {
            ans1 += binpow(q[i], (i + 1));
            ans1 %= MOD;
        }
    }
    cout << ans1 << ' ';
    rep(qu-1) {
        cin >> b;
        st ^= 1;
        if (st == 0) {
            cout << ans0 << ' ';
        } else {
            cout << ans1 << ' ';
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(6);

    int mult = 1;
    //cin >> mult;
    while (mult--)
        solve();
    return 0;
}
