#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <limits>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

const int INF = 1e9 + 7;
const ll LL_INF = 4e18;

const ll MOD = 998244353;

vector<int> revd(vector<int> arr) {
    vector<int> ans = arr;
    reverse(ans.begin(), ans.end());

    return ans;
}

ll bin_pow(ll a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return (a * bin_pow(a, p - 1)) % MOD;
    else {
        ll temp = bin_pow(a, p / 2);
        return (temp * temp) % MOD;
    }
}

vector<int> invd(vector<int> arr) {
    int n = arr.size();
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        ans[i] = n - arr[i] + 1;
    }

    return ans;
}

vector<int> get_obr(vector<int> arr) {
    int n = arr.size();
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        ans[arr[i] - 1] = i + 1;
    }

    return ans;
}

ll get_cost(const vector<int>& arr) {
    ll ans = 0;
    for (int i = 0; i < arr.size(); ++i) {
        ans += bin_pow(arr[i], i + 1);
        ans %= MOD;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, nQ;
    cin >> n >> nQ;

    map<vector<int>, bool> enc;
    vector<int> perm(n);

    for (int i = 0; i < n; ++i) {
        cin >> perm[i];
    }

    while (nQ--) {
        int type;
        cin >> type;

        if (type == 1) {
            perm = revd(perm);
        } else if (type == 2) {
            perm = invd(perm);
        } else {
            perm = get_obr(perm);
        }

        cout << get_cost(perm) << ' ';
    }

    return 0;
}