#include<bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cout << "\n!debug " << (#x) << ": " << x << "\n";
#define int long long

const int mod = 998'244'353;

void make1(int n, vector<int> &a) {
    reverse(all(a));
}

void make2(int n, vector<int> &a) {
    for (int i = 0; i < n; ++i) {
        a[i] = n+1 - a[i];
    }
}

void make3(int n, vector<int> &a) {
    vector<int> q(n);
    for (int i = 0; i < n; ++i) {
        q[a[i]-1] = i+1;
    }
    a = q;
}

int bin_pow(int num, int deg, int mod) {
    if (deg <= 0) return 1;
    if (deg % 2 == 0) {
        return bin_pow((num*num)%mod, deg/2, mod);
    }
    return (num * bin_pow(num, deg-1, mod)) % mod;
}

int calc(int n, vector<int> &a) {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int cur = bin_pow(a[i], i+1, mod);
        sum += cur;
        sum %= mod;
    }
    return sum;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int normal = calc(n, a);
    // 00, 01, 10, 11
    
    int t00 = calc(n, a);

    make2(n, a);
    int t01 = calc(n, a);

    make1(n, a);
    int t11 = calc(n, a);
    
    make2(n, a);
    int t10 = calc(n, a);

    int cnt1 = 0, cnt2 = 0;
    while (q--) {
        int t; cin >> t;
        if (t == 1) cnt1++;
        else if (t == 2) cnt2++;

        int m1 = cnt1%2, m2 = cnt2%2;
        int ans = 0;
        if (m1 == 0 && m2 == 0) {
            ans = t00;
        } else if (m1 == 0 && m2 == 1) {
            ans = t01;
        } else if (m1 == 1 && m2 == 1) {
            ans = t11;
        } else if (m1 == 1 && m2 == 0) {
            ans = t10;
        }

        cout << ans << " ";
    }
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    solve();
}