#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using ld = long double;

const int MOD = 998244353;

int sum(int x, int y) {
    if (x + y >= MOD) return x + y - MOD;
    return x + y;
} 

int mul(int x, int y) {
    return 1ll * x * y % MOD;
}

int fp(int x, int y) {
    int res = 1;

    for (; y > 0; y >>= 1) {
        if (y & 1) res = mul(res, x);
        x = mul(x, x);
    }

    return res;
}

int f(vi arr) {
    int n = arr.size();
    int res = 0;

    for (int i = 0; i < n; ++i) {
        res = sum(res, fp(arr[i], i + 1));
    }

    return res;
}

vi rev(vi arr) {
    reverse(arr.begin(), arr.end());
    return arr;
}

vi den(vi arr) {
    int n = arr.size();
    for (int &x : arr) x = n - x + 1;
    return arr; 
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    // cout << "D" << endl;

    int n, q;
    cin >> n >> q;

    vi p(n);

    for (int i = 0; i < n; ++i) cin >> p[i];

    // cout << "e "<< endl;

    vector<pair<vi, int>> perms;

    perms.pb({p, f(p)});

    int p_i = 0;

    // cout << "F" << endl;

    perms.pb({rev(p), f(rev(p))});
    int prev_i = 1;

    // cout << "F" << endl;
    perms.pb({den(p), f(den(p))});

    // cout << "F" << endl;
    int pd_i = 2;

    perms.pb({rev(den(p)), f(rev(den(p)))});

    int pdr_i = 3;
 
    // cout << "Q " << endl;

    for (int i = 0; i < q; ++i) {
        int b;
        cin >> b;

        if (b == 1) {
            swap(p_i, prev_i);
            swap(pd_i, pdr_i);
        } else if (b == 2) {
            swap(p_i, pd_i);
            swap(prev_i, pdr_i);
        } else if (b == 3) {
            //
        }

        cout << perms[p_i].second << ' ';
    }
}