#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cassert>
#include <ctime>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// #pragma GCC optimize("Ofast")
// #pragma ivdep

using namespace std;
using ll = long long;
using ld = long double;
using lll = __int128;
using pii = pair<int, int>;
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 998'244'353;

inline int fpw(ll a, ll b) noexcept {
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans = (ans * a) % mod;
            --b;
        } else {
            a = (a * a) % mod;
            b >>= 1;
        }
    }
    return ans;
}

void solve() {
    int n, q; cin >> n >> q;
    int arr[n];
    for (int& i : arr)
        cin >> i;
    int tmp[n];

    for (int _ = 0; _ < q; ++_) {
        int b; cin >> b;
        if (b == 1) {
            reverse(arr, arr + n);
        } else if (b == 2) {
            for (int i = 0; i < n; ++i)
                arr[i] = n - arr[i] + 1;
        } else {
            for (int i = 0; i < n; ++i)
                tmp[arr[i] - 1] = i + 1;
            copy(tmp, tmp + n, arr);
        }

        int ans = 0;
        for (int i = 0; i < n; ++i) {
            ans += fpw(arr[i], i + 1);
            ans %= mod;
        }
        cout << ans << ' ';
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    // cout << fpw(5, 12) << endl;

    int _ = 1;
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> _;
    #endif

    while (_--) {
        solve();
        cout << '\n';
    }

    return 0;
}
