//#define _GLIBCXX_DEBUG 1
//#pragma GCC optimize ("03, unroll-seen")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 1e18, mod = 998244353;

ll f(ll zn, ll st) {
    if (st==1)
        return zn;
    if (st%2==0) {
        ll k = f(zn, st/2);
        return k*k%mod;
    }
    if (st%2==1) {
        ll k = f(zn, st-1);
        return k*zn%mod;
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //ifstream cin ("input.txt");
    //ofstream cout ("output.txt");
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll t1 = 0, t2 = 0, t3 = 0, t4 = 0;
    for (int i = 0; i < n; i++) {
        t1 += f(a[i], i+1);
        t1 %= mod;
    }
    vector<ll> q(n);
    for (int i = 0; i < n; i++)
        q[i] = n-a[i]+1;
    for (int i = 0; i < n; i++) {
        t2 += f(q[i], i+1);
        t2 %= mod;
    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        t3 += f(a[i], i+1);
        t3 %= mod;
    }
    q.assign(n, 0);
    for (int i = 0; i < n; i++)
        q[i] = n-a[i]+1;
    for (int i = 0; i < n; i++) {
        t4 += f(q[i], i+1);
        t4 %= mod;
    }
    int cou1 = 0, cou2 = 0;
    while (m--) {
        int t;
        cin >> t;
        if (t==1)
            cou1++;
        else
            cou2++;
        cou1 %= 2, cou2 %= 2;
        if (cou1==0&&cou2==0) {
            cout << t1 << ' ';
        } else if (cou1==0&&cou2==1) {
            cout << t2 << ' ';
        } else if (cou1==1&&cou2==0) {
            cout << t3 << ' ';
        } else {
            cout << t4 << ' ';
        }
    }
}