#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#include<random>
#include<chrono> 
using namespace std;
using ll = long long;
using ld = long double;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx")

#define int long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 998244353;

int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res = a * res % mod;
        }
        n /= 2;
        a = a * a % mod;
    }
    return res;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<int> b(q);
    for (int i = 0; i < q; ++i) {
        cin >> b[i];
    }
    vector<int> p1 = p;
    vector<vector<int>> ans(2, vector<int>(2));
    for (int c = 0; c < 2; ++c) {
        for (int c1 = 0; c1 < 2; ++c1) {
            for (int i = 0; i < n; ++i) {
                ans[c][c1] += bin(p1[i], i + 1);
                if (ans[c][c1] >= mod) ans[c][c1] -= mod;
            }
            for (auto& x : p1) {
                x = n - x + 1;
            }
        }
        p1 = p;
        reverse(all(p1));
    }
    int c = 0, c1 = 0;
    for (int i = 0; i < q; ++i) {
        if (b[i] == 1) c = 1 - c;
        else if (b[i] == 2) c1 = 1 - c1;
        else {
            
        }
        cout << ans[c][c1] << '\n';
    }
}

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