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

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 998244353;

ll fstpwr(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = res * a % MOD;
        }
        n >>= 1;
        a = a * a % MOD;
    }
    return res;
}

int n;

ll calc(vector <int> & p) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = (ans + fstpwr(p[i], i + 1)) % MOD;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin >> n >> q;
    vector <int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    ll n1 = calc(p);
    bool rev = false, tr = false;
    for (int i = 0; i < n / 2; ++i) {
        swap(p[i], p[n - 1 - i]);
    }
    ll n2 = calc(p);
    vector <int> t(n);
    for (int i = 0; i < n; ++i) {
        t[p[i] - 1] = i + 1;
    }
    ll n4 = calc(t);
    for (int i = 0; i < n / 2; ++i) {
        swap(t[i], t[n - 1 - i]);
    }
    ll n3 = calc(t);
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            rev = !rev;
        } else if (type == 2) {
            tr = !tr;
        }
        if (rev && tr) {
            cout << n4 << " ";
        } else if (rev) {
            cout << n2 << " ";
        } else if (tr) {
            cout << n3 << " ";
        } else {
            cout << n1 << " ";
        }
    }
    cout << "\n";
    return 0;
}