#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pw(x) ((1LL)<<(x))
#define sz(x) (ll)x.size()
#define all(x) x.begin(), x.end()

using ll = long long;
using ld = long double;

using namespace std;

const ll N = 5e5 + 52;
const ll INF = 1e18;
const ll MOD = 998244353;

ll n, m;
ll i, j;
string s;

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // LOCAL
    ll q;
    cin >> n >> q;
    vector<ll> a(n), b(n);
    for (auto &x : a){
        cin >> x;
    }
    vector<ll> ans(10,0);
    for (i=0;i<n;i++){
        ans[0]+=binpow(a[i],i+1);
        ans[0]%=MOD;
    }
    reverse(all(a));
    for (i=0;i<n;i++){
        ans[1]+=binpow(a[i],i+1);
        ans[1]%=MOD;
    }
    reverse(all(a));
    for (i=0;i<n;i++){
        a[i] = n-a[i]+1;
    }
    for (i=0;i<n;i++){
        ans[2]+=binpow(a[i],i+1);
        ans[2]%=MOD;
    }
    reverse(all(a));
    for (i=0;i<n;i++){
        ans[3]+=binpow(a[i],i+1);
        ans[3]%=MOD;
    }
    ll tt = 0, rev=0;
    while(q--){
        ll type;
        cin >> type;
        if (type==1){
            rev++;
            rev%=2;
        }else{
            tt++;
            tt%=2;
        }
        if (tt){
            if (rev){
                cout << ans[3] << endl;
            }else cout << ans[2] << endl;
        }else{
            if (rev){
                cout << ans[1] << endl;
            }else cout << ans[0] << endl;
        }
    }
    return 0;
}
