#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,bmi2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
using lll = __int128;
const ll mod = 998244353;
ll add(ll a, ll b) {
    return (a + b) % mod;
}
ll mult(ll a, ll b) {
    return (a * b) % mod;
}
ll sub(ll a, ll b) {
    return add(a, mod - b) % mod;
}
ll pow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n & 1) ans = mult(ans, a);
        a = mult(a, a);
        n >>= 1;
    }
    return ans;
}
ll f(vector<ll> &p) {
    ll ans = 0;
    for (ll i = 0; i < p.size(); i++) {
        ans = add(ans, pow(p[i], i + 1));
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, q;
    cin >> n >> q;
    vector<ll> p(n), b(q);
    for (auto &i : p) cin >> i;
    for (auto &i : b) cin >> i;
    for (ll qi = 0; qi < q; qi++) {
        ll t = b[qi];
        if (t == 1) {
            reverse(p.begin(), p.end());
        } else if (t == 2) {
            for (ll i = 0; i < n; i++) {
                p[i] = n - p[i] + 1;
            }
        } else {
            vector<ll> p2(n);
            for (ll i = 0; i < n; i++) {
                p2[p[i] - 1] = i + 1;
            }
            p = p2;
        }
        cout << f(p) << ' ';
    }
    cout << endl;
    return 0;
}