#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define int long long

using namespace std;
using ll = long long;
ll mod = 998244353;
ll Mul(ll a, ll b) {return (a*b)%mod;}
ll Sum(ll a, ll b) {return (a+b)%mod;}
ll Sub(ll a, ll b) {return (a-b+mod)%mod;}

ll Pow(ll x, ll k) {
    ll answ = 1, step = x;
    while (k != 0) {
        if (k & 1) answ = Mul(answ, step);
        step = Mul(step, step);
        k >>= 1;
    }
    return answ;
}

ll Div(ll a, ll b) {return (a * Pow(b, mod-2))%mod;}

void solve() {
    ll n, q; cin >> n >> q;
    vector<ll> p(n), b(n);
    ll answ1 = 0, answ2 = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        answ1 = Sum(answ1, Pow(p[i], i+1));
    }
    for (int _ = 0; _ < q; _++) {
        cin >> b[_];
    }
    if (b[0] == 1) {
        reverse(p.begin(), p.end());
    } else if (b[0] == 2) {
        for (int i = 0; i < n; i++) p[i] = n - p[i] + 1;
    } else {
        vector<ll> v(n);
        for (int i = 0; i < n; i++) {
            v[p[i]-1] = i+1;
        }
        p = v;
    }
    for (int i = 0; i < n; i++) {
        answ2 = Sum(answ2, Pow(p[i], i+1));
    }
    for (int i = 0; i < q; i++) {
        cout << (i%2 == 0 ? answ2 : answ1) << " ";
    }
}

signed main() {
    cin.tie(0);
    solve();
    return 0;
}