#include "iostream"
#include "algorithm"
#include "vector"
#include "queue"
using namespace std;
#define int long long
#define all(arr) arr.begin(), arr.end()
#define _lg(x) (63 - __builtin_clzll(x))
constexpr int maxn = 200'010;
constexpr int mod = 998'244'353;
int arr[maxn]{};
int dop_arr[maxn]{};
int fpm(int x, int n, int m) {
    int ans = 1;
    while (n) {
        if (n & 1) ans = ans * x % m;
        x = x * x % m;
        n >>= 1;
    }
    return ans;
}
void solve() {
    int n, q; cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < q; i++) {
        int type; cin >> type;
        if (type == 1) {
            reverse(arr, arr + n);
        } else if (type == 2) {
            for (int j = 0; j < n; j++) {
                arr[j] = n + 1 - arr[j];
            }
        } else {
            for (int j = 0; j < n; j++) {
                dop_arr[arr[j] - 1] = j + 1;
            }
            for (int j = 0; j < n; j++) {
                arr[j] = dop_arr[j];
            }
        }
        int sum = 0;
        for (int j = 0; j < n; j++) {
            sum += fpm(arr[j], j + 1, mod);
        }
        cout << sum % mod << ' ';
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1; //cin >> t;
    while (t--) {
        solve();
    }
}