#include <bits/stdc++.h>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt")

using namespace std;
#define int long long int
#define fr(i, a, b) for(int i = (a); i <= (b); i++)
#define rf(i, a, b) for(int i = (a); i >= (b); i--)
#define fe(c, a) for (auto& c : a)
#define mk(a, b) make_pair((a), (b))
#define all(a) (a).begin(), (a).end()
template<typename T>
using v = vector<T>;
using vi = v<int>;
using vvi = v<vi>;
using ii = pair<int, int>;
using vii = v<ii>;
using vvii = v<vii>; 

const int MOD = 998244353;

int n;

vi oper1(vi& p) {
    vi q(n);
    fr(i, 0, n-1) q[i] = p[n-i-1]; 
    return q;
}
vi oper2(vi& p) {
    vi q(n);
    fr(i, 0, n-1) q[i] = n-p[i]+1; 
    return q;
}
vi oper3(vi& p) {
    vi q(n);
    fr(i, 0, n-1) q[p[i]-1] = i+1; 
    return q;
}

int bin_pow(int a, int p){
    int r = 1;
    while(p) {
        if (p&1) {
            r = (r*a)%MOD;
        }
        p>>=1;
        a = (a*a)%MOD;
    }
    return r;
}
int get_ans(vi& p) {
    int res = 0;
    fr(i, 0, n-1) res = (res + bin_pow(p[i],i+1));
    return res;
}

void solve() {
    int q; cin >> n >> q;
    vi a(n); fr(i, 0, n-1) cin >> a[i];
    int ans[2][2][2];
    fr(i, 0, 1) {
        if (i == 1) a = oper1(a);
        fr(j, 0, 1) {
            if (j == 1) a = oper2(a); 
            fr(k, 0, 1) {
                if (k == 1) a = oper3(a);
                ans[i][j][k] = get_ans(a);
                // cout << i << " " << j << " " << k << ' ' << ans[i][j][k] << '\n';
                if (k == 1) a = oper3(a);
            }
            if (j == 1) a = oper2(a);
        }
        if (i == 1) a = oper1(a);
    }
    // cout << get_ans(a) << '\n';
    array<int, 3> b = {};
    fr(i, 0, q-1) {
        int x; cin >> x; x--;
        if (x == 0) a = oper1(a);
        if (x == 1) a = oper2(a);
        if (x == 2) a = oper3(a);
        if (b[2] == 1) {
            if (x == 0) b[1]++;;
            if (x == 1) b[0]++;
        } else {
            b[x]++;
        }
        fr(i, 0, 2) b[i] %= 2;
        cout << ans[b[0]][b[1]][b[2]] << " ";
        // cout << get_ans(a) << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int t = 1; 
    // cin >> t;
    while (t--)
        solve();
}