#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdint>

#pragma GCC optimize("03")

using namespace std;

//typedef long long ll;
typedef unsigned long long ll;
const ll LINF = 1LL << 62LL;
typedef string str;
#define cin(a) for (auto &el : a) cin >> el;
#define cout(a) { for (auto &el : a) { cout << el; } cout << '\n'; }
#define endl "\n"

const ll MOD = 998244353;

ll bymod(ll a) {
    return (a + MOD) % MOD;
}

vector<ll> apply(ll b, ll n, vector<ll> v) {
    vector<ll> v_(n);
    for (ll i = 0; i < n; i++) v_[i] = v[i];
    if (b == 1) {
        for (ll i = n-1; i + 1 >= 1; i--) v[i] = v_[n-i-1];
    }
    else if (b == 2) {
        for (ll i = 0; i < n; i++) v[i] = n - v_[i] + 1;
    }
    else for (ll i = 0; i < n; i++) v[v_[i] - 1] = i + 1;
    return v;
}

ll cost(ll n, vector<ll> v) {
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ll x = 1;
        for (ll j = 1; j <= i+1; j++) {
            x *= v[i];
        }
        ans += x;
    }
    return bymod(ans);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll n, q, x; cin >> n >> q;
    vector<ll> v(n);
    //ll ans1 = 0, ans2 = 0;
    for (ll i = 0; i < n; i++) {
        cin >> v[i];
        //ans1 += pow(v[i], i+1);
        //ans2 += pow(v[i], n-i);
    }
    //ans1 = bymod(ans1); ans2 = bymod(ans2);
    while (q--) {
        ll b; cin >> b;
        v = apply(b, n, v); cout << cost(n, v) << " ";
        // if (b == 3) cout << ans1 << " ";
        // else if (b == 2 || b == 1) {
        //     cout << ans2 << " ";
        //     swap(ans1, ans2);
        // }
    }
    return 0;
}