#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(x) 67
#endif
const ll mod = 998'244'353;
ll binpow(ll a, ll p) {
    if (p == 0)return 1;
    if (p & 1) {
        return (a * binpow(a, p - 1)) % mod;
    }
    ll x = binpow(a, p / 2);
    return (x * x) % mod;
}

void solve() {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for (int &i : a)cin >> i;
    vector<int> mem;
    auto change = [&](int type) {
        mem = a;
        if (type == 1) {
            for (int i = 0; i < n; ++i) {
                a[i] = mem[n - i - 1];
            }
        } else if (type == 2) {
            for (int i = 0; i < n; ++i) {
                a[i] = n - a[i] + 1;
            }
        } else {
            for (int i = 0; i < n; ++i) {
                a[mem[i] - 1] = i + 1;
            }
        }
        mem.clear();
    };
    auto get = [&]() {
        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            ans += binpow(a[i], i + 1);
            ans %= mod;
        }
        return ans;
    };
    while (q--) {
        int b; cin >> b;
        change(b);
        debug(a);
        cout << get() << '\n';
    }
}

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
        if (tt) {
            cout << '\n';
        }
    }
}