#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define int long long

using namespace std;
using ll = long long;
ll mod = 998244353;
ll Mul(ll a, ll b) {return (a*b)%mod;}
ll Sum(ll a, ll b) {return (a+b)%mod;}
ll Sub(ll a, ll b) {return (a-b+mod)%mod;}

ll Pow(ll x, ll k) {
    ll answ = 1, step = x;
    while (k != 0) {
        if (k & 1) answ = Mul(answ, step);
        step = Mul(step, step);
        k >>= 1;
    }
    return answ;
}

ll Div(ll a, ll b) {return (a * Pow(b, mod-2))%mod;}

void solve() {
    ll n, q; cin >> n >> q;
    vector<ll> p(n);
    ll answ00 = 0, answ01 = 0, answ10 = 0, answ11 = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        answ00 = Sum(answ00, Pow(p[i], i+1));
    }
    reverse(p.begin(), p.end());
    for (int i = 0; i < n; i++) {
        answ10 = Sum(answ10, Pow(p[i], i+1));
    }
    for (int i = 0; i < n; i++) p[i] = n - p[i] + 1;
    for (int i = 0; i < n; i++) {
        answ11 = Sum(answ11, Pow(p[i], i+1));
    }
    reverse(p.begin(), p.end());
    for (int i = 0; i < n; i++) {
        answ01 = Sum(answ01, Pow(p[i], i+1));
    }

    bool rev = 0, obr = 0;
    for (int i = 0; i < q; i++) {
        ll t; cin >> t;
        if (t == 2) obr = (!obr);
        else rev = (!rev);
        if (rev == 0 && obr == 0) cout << answ00 << " ";
        else if (rev == 0 && obr == 1) cout << answ01 << " ";
        else if (rev == 1 && obr == 0) cout << answ10 << " ";
        else cout << answ11 << " ";
    }
}

signed main() {
    cin.tie(0);
    solve();
    return 0;
}