#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <random>
#define rep(n) for (int (i) = 0; (i) < (n); (i)++)
#define all(n) (n).begin(), (n).end()
#define rall(n) (n).rbegin(), (n).rend()
#define mp make_pair
#define ll long long
#define ld long double
//#define FILE

using namespace std;

const int mod = 998244353;

mt19937 gen(228);

int power(int a, int b) {
    if (b == 0)
        return 1;
    else if (b % 2 == 0) {
        int res = power(a, b / 2);
        return (ll) res * res % mod;
    }
    else
        return (ll) power(a, b - 1) * a % mod;
}

int get_ans(vector<int> A) {
    int n = A.size();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += power(A[i], i + 1);
        ans %= mod;
    }
    return ans;
}

vector<int> f(vector<int> A) {
    int n = A.size();
    int ans = get_ans(A);
    reverse(all(A));
    int ans1 = get_ans(A);
    reverse(all(A));
    rep(n) A[i] = n - A[i] + 1;
    int ans2 = get_ans(A);
    reverse(all(A));
    int ans3 = get_ans(A);
    return {ans, ans1, ans2, ans3};
}

void solve() {
    // cout << get_ans({5, 3, 1, 4, 2}) << ' ' << get_ans({2, 4, 1, 3, 5}) << ' ';
    // cout << get_ans({1, 3, 5, 2, 4}) << ' ' << get_ans({4, 2, 5, 3, 1}) << '\n';
    // cout << get_ans({3, 5, 2, 4, 1}) << ' ' << get_ans({1, 4, 2, 5, 3}) << ' ';
    // cout << get_ans({3, 1, 4, 2, 5}) << ' ' << get_ans({5, 2, 4, 1, 3}) << '\n';
    int n, q; cin >> n >> q;
    vector<int> A(n);
    rep(n) cin >> A[i];
    vector<int> ans1 = f(A);
    vector<int> B(n);
    rep(n) B[A[i] - 1] = i + 1;
    vector<int> ans2 = f(B);
    vector<vector<int>> answers{ans1, ans2};
    int x = 0, y = 0;
    while (q--) {
        int ty; cin >> ty;
        if (ty == 3)
            y ^= 1;
        else if (ty == 1)
            x ^= 1;
        else
            x = (x + 2) % 4;
        // else if (x == 0) {
        //     if (ty == 1)
        //         y ^= 1;
        //     else if (ty == 2) {
        //         y = (y + 2) % 4;
        //     }
        // }
        // else {
        //     if (ty == 1)
        //         y = (y + 2) % 4;
        //     else if (ty == 2)
        //         y ^= 1;
        // }
        cout << answers[y][x] << ' ';
    }
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "W", stdout);
#endif
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
}